Following on from above – field ‘voice_sponsored_article’ is a post object set to output post id. Modifying the query by hardcoding the post ID works as expected
function my_query_by_post_id( $query ) {
//$sponsored = get_field( 'voice_sponsored_article', 'voice_options' );//this doesn't work
$query->set( 'p', '186301' ); //this works
$query->set( 'p',$voicesponsored_link);// Nope
}
add_action( 'elementor/query/voicefilter4', 'my_query_by_post_id' );
but including the get_field line above seems to create an infinite loop.
Seems as though I need to build a meta query but unsure how to include the post id.
$meta_query[] = [
'key' => 'post_id',
'value' => get_field( 'voice_sponsored_article') //this is my intention
];
$query->set( 'meta_query', $meta_query );
This should be simple enough but I’ve yet to find an answer.
Ok Thanks. I thought I already had debugging activated but evidently not.
It’s a ACF post object set to return a post ID.
This below custom query gives me a critical page error using an ACF post object set to post ID. I’m beginning to think Elementor queries using ACF are broken, at least with my WordPress install. I’ve ran troubleshooting mode and with all plugins active the Elementor editor page loads but only when this code is commented out.
add_action( 'elementor/query/voicesponsored_filter_2', function ( $query ) {
$voicesponsored_link = get_field( 'voice_sponsored_2', 'voice_options');
$query->set( 'p',$voicesponsored_link);
} );
Thanks for that info John.
I just changed over a custom field in my homepage post loop from using elementor dynamic content -> changed to a shortcode but that rendered the homepage uneditable in elementor so definitely something going on there.
Will keep trying to find the culprit…
May I ask how you solved this? Having the same issue. I can retrieve basic text fields but Post Object fields I can’t retrieve.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.