• Resolved jamieburchell

    (@jamieburchell)


    I have a simple meta query to get all related items for the current post, but the order of results returned is not as they are set in the admin. Since there doesn’t appear to be a way of ordering by wp_postmeta.meta_id (which I think could work) I have to use this approach instead, but it requires more database calls:

    $ids = pods()->field( 'foo', [ 'output' => 'ids' ] ) ?: [ 0 ];

    return [
    'post_type' => 'foo',
    'posts_per_page' => -1,
    'post__in' => $ids,
    'order' => 'ASC',
    'orderby'=> 'post__in'
    ];

    Is there a way to do the same just using a simple meta query?

Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    IDs in relationship fields store twice, once with meta key foo in the standard WP format and again with meta key _pods_foo as a serialized PHP array in a single field

    'post__in' => get_post_meta( get_the_ID(), '_pods_foo', true ),  will return the IDs in the order of the list

    $post_in_ids = get_post_meta( get_the_ID(), '_pods_foo', true );
    if ( empty( $post_in_ids ) ) {
    $post_in_ids = [ 0 ];
    }
    return [
    'post_type' => 'foo',
    'posts_per_page' => -1,
    'post__in' => $post_in_ids,
    'order' => 'ASC',
    'orderby'=> 'post__in'
    ];
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.