Hi keubs,
No, you don’t need to include any php in this field.
There are a few ways to make this work using the_tags function (https://codex.ww.wp.xz.cn/Function_Reference/the_tags)
Easy way:
- Add a callback field to your query, and set the callback to ‘the_tags’, do not check ‘include additional information’.
- Save the field, and preview the query. You should see the tags for the posts listed.
- Save the query.
If you want to customize the output a little more, here is a slightly harder way:
- Add a callback field to your query, and set the callback to ‘my_custom_the_tags’, check ‘include additional information.
- Save the field.
- Open your theme’s function.php file (or, somewhere else you’d like to store a custom function, could be a custom plugin) and add a new function that looks like this:
function my_custom_the_tags($this_post, $field, $tokens){
// now you can add custom arguments to the_tags function here
the_tags("before tags", "between tags", "after tags");
}
- Go back to the query and preview it. You should see your custom results.
- Save the query.
This example field explains a little about the additional callback parameters that are included when you check the ‘Include Additional Information” setting for a callback field: https://gist.github.com/daggerhart/10417309
Hope this helps. Let me know if it doesn’t make sense, or you run into other issues.
Thanks,
Jonathan
Just to clarify,
In the second example, you don’t have to check “Include Additional Information” since the example custom function doesn’t make use of the $this_post, $field, or $tokens parameters.
If you didn’t need those extra parameters, and didn’t “Include Additional Information”, then the callback function would look like this:
function my_custom_the_tags(){
the_tags("before tags", "between tags", "after tags");
}
Thread Starter
keubs
(@keubs)
Hi Jonathan,
So far I’ve tried adding the callback name “the_tags” to the field, to no avail. I’m pretty green on wordpress (originally a drupal dude) so I’m learning about “the loop”. Seems like the_tags isn’t being called within the context of this query, because when I debug that function, my breakpoint only hits once despite having 4 posts. I’ll keep researching, but I provided a screenshot to see if maybe I missed something small.
Thanks
ss:
https://www.evernote.com/shard/s287/sh/b0cfd198-9bf1-475a-b65b-c4a6b28a3d95/ef56b95aad9194e9a0de208efd064214
I see your issue, you need to change the “Row Style” to “fields”. The “Post” row style is equivalent to Views “Node” row style. If the row style is “Posts”, then the fields aren’t ever rendered.
Let me know how that works out for you.
Thread Starter
keubs
(@keubs)
Ha that worked! Of course it turns out to be some rookie mistake. Thanks a ton man. I wouldn’t have gotten that far if it weren’t for your first post, and I’ll be using the custom function stuff later on in the project, so your efforts to explain weren’t completely in vain.
No worries at all. Let me know if you run into other issues.