• Resolved ejaganece

    (@ejaganece)


    Hi, thanks for the great plugin. I used it for CPT posts and it’s working fine, but i need to set featured image based on ACF field selection based condition. Can you please tell how can i set these condition based featured image.

    Thanks,
    Jagan

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi Jagan,

    That’s absolutely possible but you will have to custom code it. Depending your ACF fields. I understand you already found the code snippets for CPT.

    add_filter( 'dfi_thumbnail_id', 'dfi_acf_rough_example', 10, 2 );
    function dfi_acf_rough_example( $dfi_id, $post_id ) {
    	$post = get_post( $post_id );
    
    	$acf_field = get_field('ACF_FIELD', $post->ID);
    
    	if ( $acf_field === 'value to check' ) {
    		return 31; // the image id for the book post type.
    	}
    
    	return $dfi_id; // the original featured image id.
    }

    What value you get back does depend on the acf field type.
    Might be a string, might be an array.

    Does this help you?

    Let me know
    Jan-Willem

    Thread Starter ejaganece

    (@ejaganece)

    Thanks for the reply, I added those custom codes with ACF field value but the default CPT image only displaying. Could you please check my codes in the images ?

    Thanks,
    Jagan

    • This reply was modified 1 year, 6 months ago by ejaganece.
    Plugin Author Jan-Willem

    (@janwoostendorp)

    Hi,

    I can’t check it fully right now but it probably should work with this:

    add_filter( 'dfi_thumbnail_id', 'dfi_acf_rough_example', 10, 2 );
    function dfi_acf_rough_example( $dfi_id, $post_id ) {
    	$post = get_post( $post_id );
    	$acf_field = get_field('mbrs_palinam', $post->ID);
    
    	if ( $acf_field === 'Men' ) {
    		return 31; // the image id for the acf-gender.
    	}
    
    	return $dfi_id; // the original featured image id.
    }

    Let me know how it goes.

    • This reply was modified 1 year, 6 months ago by Jan-Willem.
    • This reply was modified 1 year, 6 months ago by Jan-Willem.
    Thread Starter ejaganece

    (@ejaganece)

    Thanks a lot, it’s working fine.

    Thanks,
    Jagan

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Option for using With CPT & ACF Select field Condition’ is closed to new replies.