• 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

    (@jrevillini)

    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

    (@jrevillini)

    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.

    Plugin Author XYDAC

    (@deepakseth)

    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

    (@jrevillini)

    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.