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.