Home Forums General Issues Metaquery not working with ACF


Metaquery not working with ACF

  • (I tried posting this a minute ago but it disappeared! trying again)

    I’m using a POST OBJECT acf field called “special_id” for a custom post type called ‘pencils’. If I remove the meta query from the args, I get the list of all Pencil posts it can find (drafts, specifically). When I add this meta_query, I get nothing back. Even though there are many draft posts with special_id “470”. I can use get_field(“special_id”, $pencil_type_id); and get the number 470 back.

    But why can’t I query for those with this (or any) matching id? Do I have a typo or something?

    $args = array(
    	    			'post_type' => 'pencils',
    	    			'post_status' => array('draft'),
    	    			'numberposts' => -1,
    	    			'meta_query'	=> array(
    	    					'relation'		=> 'OR',
    	    						'key'	 	=> 'special_id',
    	    						'value'	  	=> 470,
    	    						'compare' 	=> '=',
    	    						'key'	  	=> 'special_id',
    	    						'value'	  	=> array(470),
    	    						'compare' 	=> '=',
    	    		$posts = get_posts($args);

    get_post_meta( $some_pencil_id ) returns successfully:

    meta: Array
        [special_id] => Array
                [0] => 470
  • Solution: My posts weren’t be saved as “drafts” as I had thought. They were being saved as “Pending”

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Metaquery not working with ACF’ is closed to new replies.