• Resolved Josh Levinson

    (@joshlevinson)


    I am trying to use get_post_field to get the menu_order of posts.
    My code looks like

    $order = get_post_field($id,'menu_order','raw');

    When I do a var_dump on $order, I get an empty string.

    When I change my code to:
    $order = get_post($id)->menu_order;

    A var_dump of $order results in an int with the correct menu_order from the db. Why the difference? I even looked at the get_post_field function; it appears to be a wrapper for what my second code set does.

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

    (@bcworkz)

    I think you just got the parameter order wrong. Try:
    $order = get_post_field('menu_order', $id,'raw');

    Thread Starter Josh Levinson

    (@joshlevinson)

    Haha! I’ve been working on this project for three weeks and my mind is turning to overcooked noodles. Thanks for catching that ??

    Moderator bcworkz

    (@bcworkz)

    ?? Definitely a case of “been there, done that” for me. Nothing like a fresh set of eyes. Last thing you’d think to double check, besides, $id is always first, right? ?? Almost missed it myself!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_post_field unexpected results’ is closed to new replies.