WordPress.org

Support

Support » How-To and Troubleshooting » Limit Number of POsts in a CPT Feed

Limit Number of POsts in a CPT Feed

  • I have tried the following code but cannot get it to work, it seems the post-type check is not working, what am I doing wrong?

    If I take out the conditional,
    AND 'audio' === $wp_query->query_vars['post_type']

    it works 100% but then it will limit it for all feeds and types.

    I only want to limit to this specific CPT.

    add_filter( 'post_limits', 'podcast_post_limits_audio' );
    function podcast_post_limits_lectures( $limit )
    {
    
    	global $wp_query;
    	if ( TRUE === $wp_query->is_feed AND 'feed' === $wp_query->query_vars['feed'] AND 'audio' === $wp_query->query_vars['post_type'] )
    	{
    		return 'LIMIT 0, 2';
    	}
    	return $limit;
    }


    [Please do not create duplicate threads]

  • The topic ‘Limit Number of POsts in a CPT Feed’ is closed to new replies.
Skip to toolbar