I want to create a new plugin. This would add some meta fields for posts that are custom to the plugin. I want to make one of them accessible to the query filter on a view. What's the best way to do this?
My current thinking on the data is it will have a comma delimited list of user ids such as:
,12,16,54,
And I need the filter to pull up posts that have in this data the current viewing user id . So I was thinking of using a LIKE and having it compare this new metafield LIKE the current user id (assuming I can use a shortcode attribute to retrieve that).
Make sense and if so how do I get my new meta field to show up in the custom field drop down? Or is there a better way?
You can add custom fields using the WordPress API https://wordpress.org/support/article/custom-fields/ (update_post_meta, get_post_meta)
Those can then immediately be used in Views Queries, as they are just native WordPress Fields.
Now, if you want to create some more fancy fields than just a single line, and maybe also want them added to Toolset > Custom Fields (even if of your custom plugin), I would suggest having a look at this custom implementation here hidden link, it uses some (internal, not publicly documented) hooks of Toolset to create some Fields. That could help you in your custom development process, however, it's not something we can support in this forum.
Now, how you store your data mainly will depend on how you want to display it and search it.
Remember that if your fields are not Types fields they can't be complex (select, etc) as they would not work in Views properly (only raw values would be returned)
You can use the View query filters to filter these fields like they where single fields, that will work
Also, you can display raw values using the toolset wpv-post-field shortcode, https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153444
But this will not allow for a lot of "fancy" output, as Views could not guess any particular custom field structures, like select or so.
Please let me know if this helps planning ahead?
I think that gives me what I need. We'll see.
Almost there, added the custom fields, created a view which then filters based on a shortcode parameter. I see when I add the view it lets me fill the parameter value on the right. How do I get it to pull dynamically? I can build a shortcode but when put the shortcode in the box it doesn't work.
If there's not a way to do that (that is the ideal option), then is there a way to autofill with the current post author?
I think I figured out I had to register mycustomshortcode in the toolset settings. Sound correct?
If you use (Custom) ShortCodes in HTML conditionals, COnditional Blocks, or else, you'd have to register them in Toolset > Settings > Front End Content > Third-party shortcode arguments, that's right.
Does it work as you intended now?
I'm happy the examples made could help as a reference.
Yes, seems to be working now fine. Thank you very much