开发者

How to call particular page content using page id where post_type="page"

开发者 https://www.devze.com 2023-02-08 22:25 出处:网络
I am facing some problem in WP code. I want to show a particular page content through page id using WP function. I am using code given below. I want to fetch content having page id 37.

I am facing some problem in WP code. I want to show a particular page content through page id using WP function. I am using code given below. I want to fetch content having page id 37.

    <?php
   global $post;
   $args = array('numberposts' => 1,'post_type' => 'page');
   $myposts = get_posts($args);
    foreach( $myposts as $post ) :  setup_postdata($post); ?>
     <?php  the_block('Right Part'); ?> 
     <?php endforeach; ?>

If I am using simple query to fetch the content of page id 37.Then my <?php the_block('开发者_JS百科Right Part'); ?> function not work.

Because this function only work when we use WP functionality.


I am giving answer of my own question.

       <?php
        global $post;
        $args = array('numberposts' => 1,'post_type' => 'page', 'include'=>'37' ,);
        $myposts = get_posts($args);
        foreach( $myposts as $post ) :  setup_postdata($post); ?>
        <?php  the_block('Right Part'); ?>  
        <?php endforeach; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号