I’m using Visual Composer in WordPress and I want to make a custom Post Grid. But the default elements that the post grid supplies are not enough. I want to show the author of the post, the number of comments it has, the category it has and the Tags it has as well. I’m not really familiar with Visual Composer, but I need a point in the right direction for me to get this data? What can I do? I’ve search their documents but with no luck. If I need to move around the php code I would like to know what I’m moving around is the right thing. Any ideas? If you need any more information please do ask 😀
Thanks in advance for the help.
If anybody is still looking to find out how to to get the id in a post grid or create a specific widget for the grid you can use the following snippet I creatd for adding an icon before the post title. You will see inside the first function you can call
$post-ID
for use on any query.I got the same issue; here is how I solve it:
According to Visual Composer documentation: https://kb.wpbakery.com/docs/developers-how-tos/adding-custom-shortcode-to-grid-builder/
When you add the code below to
functions.php
, a new component will be added in your custom grid builder (in my example the name will be “Author”). There are a number of values you can get by post data template variable function and one of it not the name of the author but their ID (that’s sad but at least you can use this value to get the author name).The value is
'post_author' => ID
of the author (for example ‘1’)Here is the function where I get the post author and display it (if author component was added to your custom grid in “custom grid builder”). Put it in
functions.php
of your child theme:There is a little problem. It works but
get_the_author
is a deprecated function in WordPress. I’d appreciate any suggestions to make it more modern or if you name other alternatives please suggest.Also, here is the list of available variables of
vc_post_id_render
from docs. Here they are:this is your response
https://kb.wpbakery.com/docs/developers-how-tos/adding-custom-shortcode-to-grid-builder/
at Template variables usage
Exemple, in visual composer template you can use {{ post_date:ID }} to show post ID. I don’t know how show tag.