Support

Account

Home Forums Front-end Issues Get Post/Pages based on ACF checkbox Reply To: Get Post/Pages based on ACF checkbox

  • Hi @elliot

    Yes. i’m getting the values of current post’s checkbox via get_field, and i’m trying to find any pages which have any of current checkbox values.
    as i said, i’m trying to create something like ‘related post’ but via ACF checkbox.

    i’m not sure how i should dynamically generate the meta_query args array.

    i tried this code:

    	$checkbox_field = get_field( 'checkbox_field', $post->ID );
    	$args = array(
    		'post_type'				=> 'page',
    		'post__not_in'			=> array( $post->ID ),
    		'posts_per_page'		=> $related_no,
    		'meta_query'			=> array(
    			'relation'		=> 'OR',
    			array(
    				'key'		=> 'checkbox_field',
    				'value'		=>	$checkbox_field ,
    				'compare'	=>	'IN'
    				)
    			)
    		);

    didn’t worked.
    removing ‘relation’ => ‘AND’, adding meta_key does not have any effect on result.

    i searched whole google, but didn’t find any solution for my problem. how i should do that :S

    Thanks,
    A