Support

Account

Home Forums Add-ons Gallery Field Empty array when ordering posts by meta_value Reply To: Empty array when ordering posts by meta_value

  • I’m digging into the gallery.php code a little bit and I have a thought as to what the problem is. Let me know if this makes any sense.

    This is the code to get the attachments form the database:

    // find attachments (DISTINCT POSTS)
    $attachments = get_posts(array(
        'post_type' => 'attachment',
        'numberposts' => -1,
        'post_status' => null,
        'post__in' => $value,
    ));

    Is it possible that my $query->set( 'meta_key', 'date_published' ); is affecting this query also, since it’s using get_posts instead of making a brand new WP_Query? So in my case, it’s trying to order the attachments by date_published and since that doesn’t exist, it’s not returning anything? Will investigate further.