Forum Replies Created

  • Thanks John,
    I see where you’re going. And good caution on having too many filters/Queries.
    Using “foreach”, maybe something like this?

    // append meta query
            $meta_query = array(
              'relation' => 'AND',
    	foreach( $value as $val )
             'relation' => 'OR',
    	    'key'	=> $name,
                'value'	=> '"' . $val . '"',
                'compare'	=> 'LIKE',

    I went a different route and decided to utilize custom taxonomies, in combination with the Taxonomy field. But still utilizing the Javascript Elliot outlined in the tutorial. Seems to be less intensive query and built into WordPress already.

    Thanks again for your response.

  • add_action('pre_get_posts', 'my_pre_get_posts', 10, 1);
    function my_pre_get_posts( $query ) {
    	// bail early if is in admin
    	if( is_admin() ) return;
    	// bail early if not main query
    	// - allows custom code / plugins to continue working
    	if( !$query->is_main_query() ) return;
    	// get meta query
    	$meta_query = $query->get('meta_query');
    	// loop over filters
    	foreach( $GLOBALS['my_query_filters'] as $key => $name ) {
    		// continue if not found in url
    		if( empty($_GET[ $name ]) ) {
    		// get the value for this filter
    		// eg:,sydney
    		$value = explode(',', $_GET[ $name ]);
    		// append meta query
    	foreach( $value as $val )
        	$meta_query = [
    	     'key'		=> $name,
                'value'		=> '"' . $val . '"',
                'compare'	=> 'LIKE',
    	// update meta query
    	$query->set('meta_query', $meta_query);
  • I think I see my issue.
    Using Checkboxes and not Radio buttons. So my compare was wrong.

    As outlined here.

    However, now I have a new problem. When filtering by multiple fields, it only takes the last argument in the URL, and isn’t showing multiple posts when multiple checkboxes are selected for one field.

    Size: Small, Large
    Color: Black, White


    I need to show all that have either Small or Large, AND Black or White.
    I’m only getting results that are White (all sizes, no Black).

    Any help or direction is appreciated. Thanks for your time.

  • The plugin Smitxv mentions above : is exactly what I needed. Allowing conditional based on chosen Taxonomy ID. Maybe that should be added to future release of ACF.


  • AH!!!
    That fixed it! My other sites must of updated after the fix.
    Thanks for your help.

  • Oh Wait… It is the Wrapper Attributes at the bottom.
    Nevermind. 🙂

  • I changed over to Relationship as Post Object and that got me what I needed.
    Here is a sample that might help get you started.

    $author_id = get_the_author_meta('ID');
    $posts = get_field('field1_name', 'user_'. $author_id);
    if( $posts ):
    foreach( $posts as $post): // variable must be called $post (IMPORTANT) 
    echo '<a href="' . the_permalink() . '">' . the_title() . '</a>';
    wp_reset_postdata();  // IMPORTANT - reset the $post object so the rest of the page works correctly

    Maybe this helps someone else.

  • Changed to Post Object from Post ID.
    That fixed it!

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