I created a view containing some custom user fields. I would like to add this as an author box to my post content template for specific categories. So if the post belongs to categories x, y or z the author box should be displayed.
I got this basically working but I still have a few questions:
- How can I display this view only on posts in specific categories?
- How can I filter the view so it displays the post author? At this point I get the complete list of authors instead of just the author of the specific post.
You might find the UI intuitive enough if you try it.
In your template highlight the wpv-view shortcode then press the conditional output button.
It should be clear enough how to test for the categories in question, which will insert a wpv-conditional shortcode around your wpv-view shortcode.
Your View lists users and you want to limit it to the user who is the author of the current post.
For that insert a Query Filter for a specific user where the user is specified by a shortcode attribute (which, as you can see in the screenshot defaults to 'users').
So we are going to pass the ID of the user as an attribute in our wpv-view shortcode that inserts the View.
We can generate the ID of the author of the current post using the wpv-post-author shortcode. Insert using the Fields and Views button so that it outputs the needed attributes (see screenshot).
Your final wpv-view shortcode will look something like this:
[wpv-view name="my user view" users="[wpv-post-author format='meta' meta='ID']"]
(Note that I had to edit the wpv-post-author attributes to use single quotes.)