Query Custom Fields using meta query
-
I can’t figure out how to query posts using meta_query when the custom field has been entered using the XYDAC fields interface.
I have a custom field ‘sticky’ which is a checkbox with label ‘Yes’. Someone would check it to ‘stick’ the post to the home page. I’m developing a widget to pull the sticky posts, but I never get any posts. Here is what I was trying:
$args = array ( 'post_type' => 'events', 'numberposts' => 10, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array( array ( 'key' => 'sticky', 'value' => 'Yes', 'compare' => '=', ), ), ); $this->posts = get_posts( $args );
In the database, when the box is checked, the meta value looks like this:
a:1:{s:8:"checkbox";a:2:{s:3:"Yes";s:3:"Yes";s:10:"xydac-null";s:10:"xydac-null";}}
As a test, I created a custom field ‘test’ using the normal wordpress interface for this post type and assigned the value ‘Yes’ and was able to successfully query it using the same query above.
- The topic ‘Query Custom Fields using meta query’ is closed to new replies.