Support

Account

Home Forums ACF PRO WP_Query based on a relationship field in a Flexible Content field.

Solving

WP_Query based on a relationship field in a Flexible Content field.

  • Having some issues since upgrading to 4.9. It looks like my wp_query based on a relationship within a flexible content field stopped working. Anyone find a fix?

    function allow_wildcards( $where ) {
      global $wpdb;
      $where = str_replace(
      "meta_key = 'portfolio_flex_options_%", 
      "meta_key LIKE 'portfolio_flex_options_%",
      $wpdb->remove_placeholder_escape($where)
    );
    return $where;
    }
    
    add_filter('posts_where', 'allow_wildcards');
      $listArgs = array(
          'post_type' => 'listing',
          'posts_per_page' => 4,
          'meta_query' => array(
            //'relation'      => 'AND',
              array(
                'key' => 'portfolio_flex_options_%_brokers',
                'compare' => '=',
                'value' => $postID 
              ),
          ),
      ); 
  • I temporary solved the issues by changing % by AAA

    function my_posts_where( $where ){
    $where = str_replace("meta_key = 'courses_AAA_week_day'", "meta_key LIKE 'courses_%_week_day'", $where);
        return $where;
    }
    add_filter('posts_where', 'my_posts_where');
    
    /* my query args */
    $args['meta_query']=array(array(
                    'key'       => 'courses_AAA_week_day',
                    'value'     =>  $day,
                    'compare'   => '=',
                    'type'      => 'NUMERIC'
                ));
    /* ... */
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘WP_Query based on a relationship field in a Flexible Content field.’ is closed to new replies.