Home Forums ACF PRO query posts, filter by custom checkbox


query posts, filter by custom checkbox

  • I’m hoping someone can help me figure out what I’m doing wrong here.

    I’m trying to produce a list of “Resource” posts (custom post type) that are videos. I have a custom field checkbox for each resource with three choices of ‘sal_resource_type’ (Literature, Audio Recording, and Video.) When I use the following code, I get a list of ALL resource posts, regardless of what type or if any of the boxes are checked at all.

    I’ve tried many versions of this with no luck, and have read many others with similar questions but more complicated queries. What am I missing?

    Here’s the code as I have it now:

    // args
    $vid_args = array(
    	'posts_per_page'	=> -1,
    	'post_type'		=> 'resource',
    	'orderby' 		=> 'title', 
    	'order' 		=> 'ASC',
    	'key'			=> 'sal_resource_type',
    	'value'			=> '"Video"',
    	'compare'		=> 'LIKE'
    // query
    	$vid_query = new WP_Query( $vid_args );
    <?php if( $vid_query->have_posts() ): ?>
    	<?php while( $vid_query->have_posts() ) : $vid_query->the_post(); ?>
    		<a href="<?php the_permalink(); ?>">
    			<?php the_title(); ?>
    	<?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query();	

    When I use print_r as below:

    <?php $testTypes = get_field('sal_resource_type');

    I get results like this:
    Array ( [0] => Literature )

    What am I missing??

    Thanks in advance for any help.

    $vid_args = array(
    	'posts_per_page'	=> -1,
    	'post_type'		=> 'resource',
    	'orderby' 		=> 'title', 
    	'order' 		=> 'ASC',
    	'meta_key'			=> 'sal_resource_type',
    	'meta_value'			=> '"Video"',
    	'meta_compare'		=> 'LIKE'
  • Hallelujah! Thanks

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.