admin管理员组文章数量:1421951
I use the latest version of wordpress under php7, I use a theme that uses itself the plugin WPBakery Page Builder (based on visual composer).
I create a post that contains this:
[vc_row el_id="bloc-doc-a-telecharger"]
[vc_column]
[vc_basic_grid post_type="post" max_items="-1" style="pagination" items_per_page="4" element_width="3" arrows_design="vc_arrow-icon-arrow_09_left" arrows_position="outside" arrows_color="white" paging_color="white" item="1234" taxonomies="123"]
[/vc_column]
[/vc_row]
Shortcode so. Most of the time I can copy this kind of code and integrate it in php with do_shortcode('[my_short_code'])
but it does not work here, it shows me the message "nothing_found". This is the style="pagination"
that causes the error.
I specify that I try to integrate it in the file category.php
and that if I integrate exactly the same code in page.php
there it works.
I use the latest version of wordpress under php7, I use a theme that uses itself the plugin WPBakery Page Builder (based on visual composer).
I create a post that contains this:
[vc_row el_id="bloc-doc-a-telecharger"]
[vc_column]
[vc_basic_grid post_type="post" max_items="-1" style="pagination" items_per_page="4" element_width="3" arrows_design="vc_arrow-icon-arrow_09_left" arrows_position="outside" arrows_color="white" paging_color="white" item="1234" taxonomies="123"]
[/vc_column]
[/vc_row]
Shortcode so. Most of the time I can copy this kind of code and integrate it in php with do_shortcode('[my_short_code'])
but it does not work here, it shows me the message "nothing_found". This is the style="pagination"
that causes the error.
I specify that I try to integrate it in the file category.php
and that if I integrate exactly the same code in page.php
there it works.
- You can add your VC code in a variable then using echo apply_filters( 'the_content', $your_variable); you can get shortcode data. – Bhupen Commented Jul 4, 2019 at 13:55
- OK, just tried but it does the same... – Entretoize Commented Jul 4, 2019 at 14:11
2 Answers
Reset to default 0I finally found the problem, in fact when you add pagination to visual composer post-grid shortcode, it will use ajax to load the things. But to communicate to the ajax php script it uses the post id. The problem is that the shortcode will have no post id if you create it live, or another post id if you use an external post as a model.
Then to make it works, I first create a page with the short code I want, then in my other page I get it contents like that :
$post = get_posts(array( 'name' => 'my-page-slug','post_type' => 'page'))[0];
print do_shortcode($post->post_content);
Notice the $post
that is a global variable used by visual composer and that now have the correct post ID.
use shortcode inside single quotes as:
do_shortcode('[my_short_code]');
本文标签: theme developmentShortcode working in pagephp but not in categoryphp in wordpress
版权声明:本文标题:theme development - Shortcode working in page.php but not in category.php in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745343467a2654371.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论