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.

Share Improve this question edited Jul 4, 2019 at 14:11 Entretoize asked Jul 4, 2019 at 12:11 EntretoizeEntretoize 1331 silver badge6 bronze badges 2
  • 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
Add a comment  | 

2 Answers 2

Reset to default 0

I 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