I'm trying to create a query returning pages with a certain meta value.
Only using meta_key
works, it just doesn't work when I use both meta_key
and meta_value
.
I know the meta_value
is correct - I have double checked several times. I'm using the Custom Fields plugin and I've tried both the name, value, even copy pasting the value... so it couldn't just be that I'm using the wrong value.
Any help is very much appreciated!
Here's my query:
$skolor_query = new WP_Query(array(
'post_type' => 'page',
'meta_key' => 'program_skola',
'meta_value' => 'es'
));
if ($skolor_query->have_posts()) {
?>
<ul>
<?php while ( $skolor_query->have_posts() ) : $skolor_query->the_post();
$skola = get_the_title();
?>
<li><?php echo $skola; ?></li>
<?php endwhile;
}
?>
</ul>
$q = new WP_Query( $args );
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
?><pre><?php var_dump( get_post_meta( get_the_ID(), 'program_skola' ) ); ?></pre><?php
}
wp_reset_postdata();
}
Returns:
array (size=1)
0 =>
array (size=2)
0 => string 'sp' (length=2)
1 => string 'tp' (length=2)
array (size=1)
0 =>
array (size=3)
0 => string 'ek' (length=2)
1 => string 'es' (length=2)
2 => string 'nv' (length=2)
array (size=1)
0 =>
array (size=5)
0 => string 'ek' (length=2)
1 => string 'es' (length=2)
2 => string 'nv' (length=2)
3 => string 'sp' (length=2)
4 => string 'tp' (length=2)
get_post_meta()
so I think I can find an an ugly solution to display the pages.