Home › Forums › General Issues › PHP errors with ACF text fields › Reply To: PHP errors with ACF text fields
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.
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.