Tagged: ,

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #880773

    Hi there,
    I have two pages with posts, filtered by category.
    First page: posts with category 2014
    Second page: posts with category 2015
    The post get ordered by date, with the newest at the top.

    I would like to show one post on both pages: in 2014 as an announcement, in 2015 as a reminder.
    As this post was the last in 2014 it should get to the top. This also works.
    But in 2015 this post should be the last while oldest – but it also gets displayes first.

    How can I solve this?

    Best regards
    Marko

    #881214

    Hey mkuzman,

    Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?

    Best regards,
    Victoria

    #882142
    This reply has been marked as private.
    #882509

    Hi,

    Thank you for the info. What is the login url? The default “wp-admin” or “wplogin” is not working. Please try to use the “pre_get_posts” filter. Example.

    function ava_conditional_pre_get_posts_order( $query ) {
    	if ( is_admin() || ! $query->is_main_query() )
    		return;
    
    	if ( is_page(3827) ) {		
    		$query->set( 'orderby', 'date' );
    		$query->set( 'order', 'ASC' );
    	}
    
    	if ( is_page(3824) ) {
    		$query->set( 'orderby', 'date' );
    		$query->set( 'order', 'DESC' );		
    	}
    
    	return;
    }
    add_action( 'pre_get_posts', 'ava_conditional_pre_get_posts_order', 1 );

    Adjust the value as necessary.

    // https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    Best regards,
    Ismael

    #882777
    This reply has been marked as private.
    #883427

    Hi,

    Thank you for the update. We added the filter in the functions.php file.

    Best regards,
    Ismael

    #883450

    Hi Ismael,
    thank you – now it seems to work.
    Best regards
    Marko

    #883770

    Hi,

    Awesome. Let us know if you need anything else. :)

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Post order when displaying in more categories’ is closed to new replies.