questions

Query part of ACF text field inside a Custom Post Type

Rate this post

 

I can successfully query the ACF text field if i was to match the text exactly (if the job title was ‘Manager’ and I query ‘Manager’).

How do I do I query the same ACF field, but if I was to search for ‘anage’ or ‘Mana’ then the ‘Manager’ field would return?

This is my current code. I have tried replacing ‘value’ with ‘s’, but I’m not sure that can be done inside a meta_query.

<?php if ($_GET['jobtitle']){
    $get_title = filter_var( $_GET['jobtitle'], FILTER_SANITIZE_STRING );
    if ( ! empty( $get_title ) ) {
        $meta_query[] = array(
            'key' => 'job_title', //Name of the acf
            'value' => $get_title,
        );
    }
} ?>

And this is my current Query (although i suspect this part is irrelevant)

<?php $the_query = new WP_Query(array(
        'post_type'         => 'team',
        's'                 => $get_person,
        'meta_query'        => $meta_query,
        'order'             => 'ASC',
        'orderby'           => 'menu',
        'posts_per_page'    => -1
      )); 
if ( $the_query->have_posts() ) : ?>

 

✔️Solution:

'compare'   => 'LIKE' 

Easy as that. Added this line below ‘value’

Leave a Reply

Your email address will not be published.

Back to top button