Support

Account

Home Forums Backend Issues (wp-admin) Query Posts by ACF Value in Functions.php Reply To: Query Posts by ACF Value in Functions.php

  • Hi John,

    Thanks for getting back to me.

    Fortunately, I was able to echo out the post content based on the ACF drop-down selection. I had to make a couple of alterations for this to work though, so it’s not as automated as I was hoping for.

    So basically I changed the custom field type from Post Object to Select and just inserted a list of post IDs along with their respective guide names.

    I then altered the PHP in functions to this:

    //Add a guide
    add_action( 'woocommerce_product_thumbnails', 'gotread_guide', 110 );
    
    function gotread_guide() {
    	echo '<div class="row clear">';
    	echo '<div class="col-4">';
    
    	echo '</div>';
    	echo '<div class="col-8">';
    		$guideid = get_field('choose_your_guide', false, false);
    		$post_id = $guideid;
    		$queried_post = get_post($post_id);
    		$title = $queried_post->post_title;
    		echo $title;
    		echo $queried_post->post_content;
    	echo '</div>';
    	echo '</div>';
    }

    A new variable of $guideid was added which was equal to get_field('choose_your_guide', false, false); I realised it wasn’t working before because it was echoing the ID as a string rather than a number so adding false to the $format_value parameter stopped this. Which is pulling out both the title and the post content. Which is great, but you’re right I am having trouble with the images.

    I want to echo out the featured image. How would you recommend I go about this using JavaScript?