Support

Account

Forum Replies Created

  • Just to clarify for anyone who comes across this later:

    My pre_get_posts action was setting query parameters not just for the main query (as I intended) but also the query by the Gallery plugin that gets the attachment data. These query parameters caused the get_posts query in gallery.php to return nothing.

  • I just came across that at the same time that you posted it. That works! Thank you!

  • I did some debugging in gallery.php and found that the issue his happening in the format_value function. The $value variable has the IDs of the attachments as it should, but when the get_posts query is run to get the data from those attachments, nothing is returned. I’m thinking my theory about the $query->set calls messing with the get_posts query. I’m going to see if I can tweak it and make it work.

  • Fortunately the typo was only in my comment here and not in my code. That’d have been infuriating!

  • 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.

  • What are you doing inside your pre_get_posts action? I don’t believe it’s the pre_get_posts action that’s causing the problem. If I just have it echo out some text, get_field returns an array of images as expected. It’s when I modify the query by adding $query->set( 'meta_key', date_published' ); that I run into a problem.

  • If you have any other suggestions of debugging I should try I’d definitely love to hear them. I’m afraid it might be some kind of bug in the way that ACF and WP interact in this extremely specific instance and I don’t have a terribly large amount of time to dig around in Core…this is on a client site with a fairly tight deadline.

  • (This is going to be interesting to work out since we’re in basically opposite time zones)

    I will check the $post-ID in the morning when I get to the office, as well as testing a basic function, but everything else for the post is displaying properly…the name, permalink, even other metadata I’ve set using ACF and am accessing with get_field(). The ONLY thing that isn’t working is that the gallery is returning an empty array rather than an array of images.

    I am certain that the posts have gallery data, because on their individual pages the gallery is being displayed fine, and when I remove my pre_get_posts filter, the galleries show up on the correct posts.

    Thanks,
    Ryan

Viewing 8 posts - 1 through 8 (of 8 total)