Okay
  Public Ticket #2797021
The order of the blog pages
Closed

Comments

  • spider-web started the conversation

    Dears,
    Wondering how to display blog pages by publication date?
    The first two blog posts were displayed in order of publication, but when I posted the third post, for some reason it appears in the middle of the list.

  •  933
    Neuron replied

    Hi,

    Can you please provide me with your wp-admin, I will have a quick look to see what's going on, make sure to click on private reply.

    Feel free to ask for anything you need.

    Kind Regards


  •   spider-web replied privately
  •  933
    Neuron replied

    Hi,

    I've added the following script at the functions.php file of the Child theme, and now it seems to be alright.

    function prefix_modify_query_order( $query ) {
      if ( is_main_query() ) {
     
        $args =  array( 'post_date' => 'ASC' );
     
        $query->set( 'orderby', $args );
      }
    }
    add_action( 'pre_get_posts', 'prefix_modify_query_order' );

    Feel free to ask for anything you need.

    Kind Regards


  • spider-web replied

    Thank you Neuron.
    It would be more logical to display blog pages starting with the most recent entry and ending with the oldest. No one would want to open a blog section and see the same oldest posts again... If we'll have for example 10 posts, then we would like to show the most recent on the first page, the next 3 on page 2, and latest - on page 3, etc.
    Would it be possible to change the order, please?

  •  933
    Neuron replied

    Hi,

    I've just updated the code, so now the latest one is showing as the first post.

    Feel free to ask for anything you need.

    Kind Regards


  • spider-web replied

    Brilliant! Thank you very much. Have a nice day!

  •  933
    Neuron replied

    You are welcome anytimesmile.png, feel free to ask for anything you need

    Kind Regards,
    NeuronThemes


  • spider-web replied

    One end fixed, the other collapses... :(
    After fixing the order of blog pages,  also the product order were changed. So I tried to arrange then manually, but id doesn't work anymore - the products also rearranges by publishing date. Could we leave possibility to order product pages manually, please?

  •  933
    Neuron replied

    Hi,

    I am very sorry for the late reply, we were not working on the weekend.

    While I was doing some changes to the code that I've added, I've made a mistake and there was a typo in the code, so can you please go to the Child theme files > functions.php and remove the part of the code that I've added.

    The code that you should remove is the following one.

    function prefix_modify_query_order( $query ) {
      if ( is_main_query() {
     
        $args =  array( 'post_date' => 'ASC' );
     
        $query->set( 'orderby', $args );
      }
    }
    add_action( 'pre_get_posts', 'prefix_modify_query_order' );
    

    After you remove this part of the code, please let me know, so I can log in and fix this.

    Feel free to ask for anything you need.

    Kind Regards


  • spider-web replied

    Hi,
    I removed the code that you wrote below from Child theme files > functions.php. 

  •  933
    Neuron replied

    Hi,

    I've added the code back again, can you please check it now.

    Feel free to ask for anything you need.

    Kind Regards


  • spider-web replied

    Hi,

    Yes, the order of blog pages are OK now, but the order of the products becomes messy (the order of the products was also changed when you added the code). I tried to arrange then manually once again, but id doesn't work anymore - the products also rearranges by publishing date. Could we leave possibility to order product pages manually, please? The order of the products are more important for as then the order of blog pages.

  •  933
    Neuron replied

    Hi,

    I'm so sorry for the late reply,

    Can you please remove the code that I've added before at the functions.php file and add the following one instead.

    function prefix_modify_query_order( $query ) {
      if ( is_page('blog') ) {
     
        $args =  array( 'post_date' => 'ASC' );
     
        $query->set( 'orderby', $args );
      }
    }
    add_action( 'pre_get_posts', 'prefix_modify_query_order' );

    Feel free to ask for anything you need.

    Kind Regards


  • spider-web replied

    Hi,

    I remove the code that I've added before and added a new one at the Child theme files > functions.php file.

    Now everything has become as it was in its initial state (without any code): the order of products are OK now (sortable again), but blog pages somehow are still not in order.

  • spider-web replied

    Looks like I already find and fixed the issue. I changed "blog" to "tinklarastis"  and the code works now.

    function prefix_modify_query_order( $query ) {
      if ( is_page('tinklarastis') ) {
     
        $args =  array( 'post_date' => 'ASC' );
     
        $query->set( 'orderby', $args );
      }
    }
    add_action( 'pre_get_posts', 'prefix_modify_query_order' );


  • spider-web replied

    Just found another issue: as I already mentioned, I would like to display blog pages starting with the most recent entry and ending with the oldest. The code did just the opposite. But I already find a solution to this issue, too (writing just in case if someone reads this public ticket and wants to take advantage of the solution): "ASC" changed to 'DEC' in the code: 

    function prefix_modify_query_order( $query ) {
      if ( is_page('tinklarastis') ) {
     
        $args =  array( 'post_date' => 'DEC' );
     
        $query->set( 'orderby', $args );
      }
    }
    add_action( 'pre_get_posts', 'prefix_modify_query_order' );


    NB: blog = tinklarastis in my local language I use for my webpage, so this was a reason I must change the code accordingly (no need to do so for the those who use English)

  •  933
    Neuron replied

    Hi,

    Very glad to know that you've managed to fix this onesmile.png

    Feel free to ask for anything you need.

    Kind Regards