最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

array - How can I get the content of the current page in my loop while merging post-type

programmeradmin3浏览0评论

I made a loop which is loading post-type. But while it is loading basic post and post-type, it is not loading the main content of the page. I am searching for a way to load the current page content while loading my post-type.

How can I do that ?

global $wp_query;
        $args = array_merge( $wp_query->query, array( 'post_type' => array('post','Projets'), 'posts_per_page' => 3, ) );
        if ( query_posts($args) ) :

        while ( have_posts() ) : the_post();
        get_template_part( 'template-parts/content', 'content' )

        endwhile;
        else :
            get_template_part( 'template-parts/none', 'none' );
        endif;

I made a loop which is loading post-type. But while it is loading basic post and post-type, it is not loading the main content of the page. I am searching for a way to load the current page content while loading my post-type.

How can I do that ?

global $wp_query;
        $args = array_merge( $wp_query->query, array( 'post_type' => array('post','Projets'), 'posts_per_page' => 3, ) );
        if ( query_posts($args) ) :

        while ( have_posts() ) : the_post();
        get_template_part( 'template-parts/content', 'content' )

        endwhile;
        else :
            get_template_part( 'template-parts/none', 'none' );
        endif;
Share Improve this question asked Apr 7, 2020 at 16:52 YagayenteYagayente 1011 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Ok solved it like this :

<?php

$mainquery = get_queried_object();

$args = array(
'pagename' => 'Accueil' //as my home page
);

$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
?>
     <div class="entry-content">
                <?php
the_content(); // here I can load my content
?>
     </div><br><br>

<?php
}
}

wp_reset_postdata();

global $wp_query;
$args = array_merge($wp_query->query, array(
'post_type' => array(
'post',
'Projets'
),
'posts_per_page' => 3
));
if (query_posts($args)):
while (have_posts()):
the_post();
get_template_part('template-parts/content', 'content');
endwhile;
else:
get_template_part('template-parts/none', 'none');
endif;
?>
发布评论

评论列表(0)

  1. 暂无评论