Skip to main content
edited body
Source Link

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Update: This args are working as intended:

// WP_Query arguments.
$featured = array(
    'posts_per_page' => '5',
    'cat'            => '1',
    'meta_key'       => 'positor_featured_post''mytheme_featured_post',
    'meta_value'     => '1',
);

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Update: This args are working as intended:

// WP_Query arguments.
$featured = array(
    'posts_per_page' => '5',
    'cat'            => '1',
    'meta_key'       => 'positor_featured_post',
    'meta_value'     => '1',
);

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Update: This args are working as intended:

// WP_Query arguments.
$featured = array(
    'posts_per_page' => '5',
    'cat'            => '1',
    'meta_key'       => 'mytheme_featured_post',
    'meta_value'     => '1',
);
deleted 246 characters in body
Source Link

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

AddonUpdate: The code runs from index.php over the main loop.This args are working as intended:

<?php get_header(); ?>
<div class="container">
        
        

    <?php /* Grid with featured posts */
        get_template_part( 'components/post/grid' );
   WP_Query arguments.
            if ( is_home() && is_front_page() &&$featured != is_pagedarray() ) {
                get_template_part('posts_per_page' 'components/post/grid'=> );'5',
           'cat' }
           => ?>'1',
     'meta_key'       <?php
   => 'positor_featured_post',
         'meta_value'   if ( have_posts()=> '1',
) : // The main loop;

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Addon: The code runs from index.php over the main loop.

<?php get_header(); ?>
<div class="container">
        
        

    <?php /* Grid with featured posts */
        get_template_part( 'components/post/grid' );
    
            if ( is_home() && is_front_page() && ! is_paged() ) {
                get_template_part( 'components/post/grid' );
            }
            ?>
            <?php
    
            if ( have_posts() ) : // The main loop

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Update: This args are working as intended:

// WP_Query arguments.
$featured = array(
    'posts_per_page' => '5',
    'cat'            => '1',
    'meta_key'       => 'positor_featured_post',
    'meta_value'     => '1',
);
added call code
Source Link

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Addon: The code runs from index.php over the main loop.

<?php get_header(); ?>
<div class="container">
        
        

    <?php /* Grid with featured posts */
        get_template_part( 'components/post/grid' );
    
            if ( is_home() && is_front_page() && ! is_paged() ) {
                get_template_part( 'components/post/grid' );
            }
            ?>
            <?php
    
            if ( have_posts() ) : // The main loop

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

I am trying to show the featured posts in my theme, with a custom field mytheme_featured_post which is 1 on the featured posts.

However it does not seem to filter the posts down to only the posts in the meta query.

// WP_Query arguments.
$featured = array(
'posts_per_page' => '5',
'meta_query' => array(
    array(
        'key'     => 'mytheme_featured_post',
        'value'   => '1',
    ),
),
);

// The Query.
$featured_query = new WP_Query( $featured );

if ( $featured_query -> have_posts() ) {
    while ( $featured_query -> have_posts() ) : $featured_query -> the_post();
        the_title();
    endwhile;
}

Addon: The code runs from index.php over the main loop.

<?php get_header(); ?>
<div class="container">
        
        

    <?php /* Grid with featured posts */
        get_template_part( 'components/post/grid' );
    
            if ( is_home() && is_front_page() && ! is_paged() ) {
                get_template_part( 'components/post/grid' );
            }
            ?>
            <?php
    
            if ( have_posts() ) : // The main loop
clarified title
Link
Loading
Source Link
Loading