WordPress.org

Ready to get started?Download WordPress

Forums

Ultimate Post Type Manager
Query Custom Fields using meta query (5 posts)

  1. James Revillini
    Member
    Posted 2 years ago #

    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.

  2. James Revillini
    Member
    Posted 2 years ago #

    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 );
  3. James Revillini
    Member
    Posted 2 years ago #

    Looks like this may not be possible to accomplish.

    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.

  4. XYDAC
    Member
    Plugin Author

    Posted 2 years ago #

    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..:)

  5. James Revillini
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic