Support

Account

Home Forums ACF PRO Query posts for a relationship value fallback issues

Helping

Query posts for a relationship value fallback issues

  • Hi,

    I am using the meta_query LIKE to match an author value “Joe Blogs” to the database value stored on in a relationship field, however If there is no match within the LIKE comparison, the meta_query still produces a wild card result similar to if the comparison condition was not set at all.

    If am trying to find a possible solution that if no result is provided from the meta_query then it would fall back to a tax_query so as a result wold always be possible.

    
    $articles = new WP_Query(
        array(
            'post_type' => 'article',
            'orderby' => 'posted_date',
            'order' => 'DESC',
            'post_status' => 'publish',
            'posts_per_page' => $totalRecordsToDisplay,
            'meta_query' => array (
                array(
                    'key' => 'authors', // relationship field
                    'value' => '"' . get_the_ID() . '"',
                    //'value' => $post->post_title,
                    //'value' => get_the_id(),
                    'compare' => 'LIKE'
                )
                    
    
            ),
            'tax_query' => array(
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'expertise',
                        'field' => 'term_id',
                        'terms' => array(join(",", wp_list_pluck($expertises, 'term_id'))),
                        'include_children' => true
                    )
                )
            ),
    
        )
    );
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.