WordPress.org

Forums

Featured Post
Showing non-featured posts (5 posts)

  1. MathieuRbrt
    Member
    Posted 2 years ago #

    Hi,
    I'm using your plugin and it's working great to display featured posts, but what if I'd like to show beside them just the regular posts?

    I tried the query :
    query_posts($query_string."&featured=no");

    But it is still showing up featured posts..

    Do you guys know what to do?
    Thanks in advance
    Mathieu

    http://wordpress.org/extend/plugins/featured-post/

  2. aunrea
    Member
    Posted 2 years ago #

    You shouldn't use query_posts for multiple queries.

    Show featured posts by...

    <?php $args = array(
        'featured' => 'yes'
    );
    $featured = new WP_Query($args);
    if($featured->have_posts()): while($featured->have_posts()): $featured->the_post();?>
    Featured posts stuff...
    <?php endwhile; endif; wp_reset_postdata();?>

    Then show regular posts by...

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    Post content...
    <?php endwhile; endif; ?>
  3. MathieuRbrt
    Member
    Posted 2 years ago #

    Thanks, but the thing I want is show all the NON-featured posts, do you know how to do that ? featured => no doesn't work

  4. PDM@WP
    Member
    Posted 2 years ago #

    Hi Matthieu,

    I am newbie in WP but i had the some problem and locked into the plugin code. I have changed pre_get_posts function and worked for me. Hope this can help.

    ps. Sovit thanks for your plugin - it's very intuitive for the End user

    function pre_get_posts( $query )
    	{
    		if ( !is_admin() ) {
    			if ( $query->get( 'featured' ) == 'yes' ) {
    				$query->set( 'meta_key', 'featured' );
    				$query->set( 'meta_value', 'yes' );
    			}
    			else if ( $query->get( 'featured' ) == 'no' ) {
    
    				$metaquery = array(
    					'relation' => 'OR',
    					array(
    						'key' => 'featured',
    						'value' => 'yes',
    						'compare' => '!='
    					),
    					array(
    						'key' => 'featured',
    						'value' => '',
    						'compare' => 'NOT EXISTS'
    					)
    				);
       				$query->set( 'meta_query', $metaquery );
    
    			}
    		}
    		return $query;
    	}
  5. PDM@WP
    Member
    Posted 2 years ago #

    UPDATE:You should also update the admin_ajax function. Please see below

    function admin_ajax( )
    	{
    		$post_id     = $_POST[ 'post_id' ];
    		$is_featured = get_post_meta( $post_id, 'featured', true );
    		$newStatus   = $is_featured == 'yes' ? 'no' : 'yes';
    		delete_post_meta( $post_id, 'featured' );
    		if ($newStatus=="yes")
    			add_post_meta( $post_id, 'featured', $newStatus );
    		echo ":P";
    		die( );
    	}

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Featured Post
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic