Get_field() not working in PHP Query Editor?

Hi there,

I wrote below PHP for the query editor. The query works fine if I replace the 2 instances of get_field with static values. The ACF fields should be valid, and I no error notifications. It just won’t produce anything.

Any ideas?

return array(
  'post_type'      => 'page-section',  
  'posts_per_page' => 1,  
  'meta_key'       => 'volgnummer',  
  'orderby'        => 'meta_value_num',  
  'offset'         => get_field('acf_volgnummer'),
  'order'          => 'ASC',
  'meta_query'     => array(
    array(
      'key'     => 'page_urlslug',
      'value'   => get_field('acf_url_slug'),
      'compare' => '='
    ),
  ),
);

Hey @GuiT,

is it just an in-builder issue? Or is it also not working on the frontend? Can you try to use {post_id} as the second argument to the get_field function?

get_field( 'acf_volgnummer', {post_id} )

Best,

André

Hi André, thanks for your reply.

The front end shows nothing (except for a starting ‘hero’ block.) above the point where this query is running.
I tried to insert a valid post_id, but still nothing.

Like I said, using straight values works fine. Also using the Query Panel from the builder works well, except for on thing: the offset can not me dynamic. Since I have this in a template that will be used on many pages and multiple times per page, it makes me manually change the offset, for about 150 instances :frowning:

Any other suggestions?

Greetz, Gui

Hey @GuiT,

you could just do it like this and use the bricks/posts/query_vars hook to dynamically set the offset.

Best,

André

That looks promising! I’ll give it a try.
Thanks a lot!

Greetz, Gui