Support

Account

Home Forums Front-end Issues display posts based on a value within a checkbox array

Solved

display posts based on a value within a checkbox array

  • I’m using the following arguments for a wp_query that produces posts with a radio button value that match the page title:

    $title = get_the_title();
    $args = array(
        'numberposts' => -1,
        'post_type' => 'activities',
        'post_status' => 'publish',
        'meta_query' => array (
    			array (
    		  		'key' => 'day',
    		  		'value' => $title,
                                    'compare' => 'IN'
    		    )
    		  ) );
    

    However, what I actually need is multiple checkbox options on the posts so that the same post can appear on multiple pages if ‘checked’.

    For example, the checkbox array may contain the values ‘Monday’, ‘Tuesday’ and ‘Wednesday’ – these values correspond to pages on site.

    I’ve added the checkbox custom field but how do I change this code so that wp_query returns posts that have a checkbox value matching the page title?

    Many thanks for any advice.

    John

  • I’ve fixed this via the ACF documentation – http://www.advancedcustomfields.com/resources/query-posts-custom-fields/.

    Using the ‘LIKE’ compare value in the meta_query array:

      $args = array(
        'numberposts' => -1,
    		'post_type' => 'activities',
        'post_status' => 'publish',
    		'meta_query' => array (
    			array (
    		  		'key' => 'day_of_the_week',
    		  		'value' => $title,
              'compare' => 'LIKE'
    			)
    		  ) );
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘display posts based on a value within a checkbox array’ is closed to new replies.