I’m searching how to keep the featured post in my blog homepage without excluding it from query post. My blog uses the Twenty Fourteen theme. I found this solution.

Open the featured-content.php from your theme’s inc folder, and look for the following code (line 269 in our case).

$query->set( 'post__not_in', $featured );

Simply comment out this line, by adding two slashes in front of it, to get this:

// $query->set( 'post__not_in', $featured );

But the file doesn’t have that line and the child theme cannot override the parent theme’s inc folder.

I have found another solution and it works, but, the problem is this code show the featured content post not in their original order. When old content post – I’m using sticky post to make featured post – become featured, the featured content post will become the first order then the other post.

I have try using conditional tag like this.

function show_featured_content_on_home() {
if ( !is_home() ) {
remove_action( 'pre_get_posts', array( 'Featured_Content', 'pre_get_posts' ) );
    }
}
add_action( 'init', 'show_featured_content_on_home', 31 );

The second page and so on okay – show the featured posts in order – but the homepage still have problem.

Any suggestions?

1

I think you can use the WPQuery

    $the_query = new WP_Query( array( 'post__in' => get_option( 'sticky_posts' )) ); ?>

    <?php if ( $the_query->have_posts() ) : ?>

        <!-- pagination here -->

        <!-- the loop -->
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>   
<h2><?php the_title(); ?></h2>
        <?php endwhile; ?>
        <!-- end of the loop -->

        <!-- pagination here -->

        <?php wp_reset_postdata(); ?>


    <?php endif; ?>

and for ordering your post you can use order and orderby see reference
https://codex.wordpress.org/Class_Reference/WP_Query

Leave a Reply

Your email address will not be published. Required fields are marked *