Trying to add "order" function to posts... (2 posts)

  1. Esther
    Posted 9 months ago #

    I'd like for my posts to appear in a certain order on category pages, which theoretically is possible by only slightly modifying the snippet from the add_post_type_support in function reference here like this:

    add_action('init', 'my_custom_init');
    function my_custom_init() {
    	add_post_type_support( 'post', 'page-attributes' );

    The meta-box for "order" comes up and it saves, but unfortunately doesn't affect the order in which the posts appear.
    Anybody have any ideas how to make it happen?

    Thanks in advance!

  2. bcworkz
    Posted 9 months ago #

    The Order page attribute typically only applies to the post list table in the admin area, and only to hierarchical posts, of which regular posts are not.

    Still, the value is saved as you noted, so a theme could potentially make use of this value in listing posts or pages. It sounds like your theme does not support this, which is quite typical. You could create a child theme (or make a simple plugin) that alters category queries to orderby 'menu_order' in the 'pre_get_posts' action.


You must log in to post.

About this Topic