Title: Query Custom Fields using meta query
Last modified: August 20, 2016

---

# Query Custom Fields using meta query

 *  [James Revillini](https://wordpress.org/support/users/jrevillini/)
 * (@jrevillini)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/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.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [James Revillini](https://wordpress.org/support/users/jrevillini/)
 * (@jrevillini)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query-custom-fields-using-meta-query/#post-2246316)
 * Hah. I decided to try this query instead and it worked. Is there an easier way?
 *     ```
       $args = array (
       	'post_type' => 'events',
       	'numberposts' => 10,
       	'orderby' => 'date',
       	'order' => 'DESC',
       	'meta_query' => array(
       		array (
       			'key' => 'sticky',
       			'value' => 'a:1:{s:8:"checkbox";a:2:{s:3:"Yes";s:3:"Yes";s:10:"xydac-null";s:10:"xydac-null";}}',
       			'compare' => '=',
       		),
       	),
   
       );
       $this->posts = get_posts( $args );
       ```
   
 *  Thread Starter [James Revillini](https://wordpress.org/support/users/jrevillini/)
 * (@jrevillini)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query-custom-fields-using-meta-query/#post-2246319)
 * Looks like this may not be possible to accomplish.
 * [http://wordpress.stackexchange.com/questions/16709/meta-query-with-meta-values-as-serialize-arrays](http://wordpress.stackexchange.com/questions/16709/meta-query-with-meta-values-as-serialize-arrays)
 * Can you think of other ways? I’m trying to avoid pulling more than I need and
   doing the filter in PHP if I can help it.
 *  Plugin Author [XYDAC](https://wordpress.org/support/users/deepakseth/)
 * (@deepakseth)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query-custom-fields-using-meta-query/#post-2246465)
 * Hie,,
    I have seen people having various issues using the serialized values in
   meta data. I have decided to revert them back to normal form which i’ll be doing
   in next release.
 * Hope you can wait till then..:)
 *  Thread Starter [James Revillini](https://wordpress.org/support/users/jrevillini/)
 * (@jrevillini)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/query-custom-fields-using-meta-query/#post-2246534)
 * That is going to be AWESOME! I can absolutely wait. If you want any help, just
   let me know what I can do. I’m a PHP/Wordpress guru and I’m good about following
   another programmer’s coding conventions.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Query Custom Fields using meta query’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ultimate-post-type-manager.svg)
 * [Ultimate Post Type Manager](https://wordpress.org/plugins/ultimate-post-type-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-post-type-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-post-type-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-post-type-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-post-type-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-post-type-manager/reviews/)

## Tags

 * [meta_query](https://wordpress.org/support/topic-tag/meta_query/)

 * 4 replies
 * 2 participants
 * Last reply from: [James Revillini](https://wordpress.org/support/users/jrevillini/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/query-custom-fields-using-meta-query/#post-2246534)
 * Status: not resolved