0

I am making a page template that should display custom post-types that have meta value that matches the page title. Meta value is added trough Advanced Custom Field radio buttons, but the query is not taking the meta into consideration, it's displaying all the posts. I've checked $name stores the correct string, posts have the correct value for program key.

Here is the query code:

$name = get_the_title(get_the_ID());
$args = array(
    'post_type' => 'project',
    'posts_per_page' => -1,
    'meta_query' => array(
            'key' => 'program',
            'value' => $name,
            'compare' => 'LIKE'
        ) 
    );
$projects_q = new WP_Query($args);

I've even tried to wrap the 'value' value in "" and change the $name to lower case but the result is the same.

$name = strtolower(get_the_title(get_the_ID()));
$args = array(
    'post_type' => 'project',
    'posts_per_page' => -1,
    'meta_query' => array(
            'key' => 'program',
            'value' => '"' . $name . '"',
            'compare' => 'LIKE'
        ) 
    );
$projects_q = new WP_Query($args);

Is there some special way to query posts with radio buttons?

1

I tried with regular meta_key - meta_value pair and it works as it should...

$name = get_the_title(get_the_ID());
$args = array(
    'post_type' => 'project',
    'posts_per_page' => -1,
    'meta_key' => 'program',
    'meta_value' => $name,
    );
$projects_q = new WP_Query($args);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.