• Hello

    I have created a shortcode that I use in our site. The purpose of the shortcode is to display posts, nothing special, but I want to sort them by menu order.

    So I added in the functions.php the bellow code

    
    add_action( 'admin_init', 'MenuOrder_OnPosts' );
    
    function MenuOrder_OnPosts() 
    {
      add_post_type_support( 'post', 'page-attributes' );
    }
    

    But when I’m in the admin inside a post and set a number on the attribute and click save the number resets to zero…

    What can I do to solve this problem?

    Thanks is advance,
    Olga

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I think menu order is only applied to hierarchical post types. In a post, the field value is not even sent as part of the POSTed data, so the field is essentially unusable. My advice is to use a custom field to define ordering. Ordering a posts query by a meta value is not uncommon.

    Thread Starter olgamm

    (@olgamm)

    Hello, thank you for your answer.
    How do I apply custom field to a post ??

    Moderator bcworkz

    (@bcworkz)

    There should be a custom fields meta box (aka document panel) below the post editor. If you don’t see one, use the 3 dot icon at upper right, then pick Options. Check mark Custom Fields near the bottom of the resulting dialog.

    In the meta box, click the Enter New link. Enter a Name and Value, then click the Add Custom Field button. Once you’ve defined a name, when adding the field in other posts, just select the same name in the Name drop down.

    Then when you query for posts, set the query arg “meta_key” to be the chosen name and set “orderby” arg to be “meta_value_num” (assuming you are saving numeric ordering data).

    Thread Starter olgamm

    (@olgamm)

    Okay I will check this out 🙂
    Thank you for your answer!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Orderby – Menu Order on Posts’ is closed to new replies.