• Resolved fograinfall

    (@fograinfall)


    I am trying to create a custom filter to find a custom post by a custom field value. Currently I have having trouble getting the GraphiQL IDE to return any results based on stopNumber in the following structure.

    query QueryStop {
      sgstops(where: {stopNumber: 171}) {
        nodes {
          guideFields {
            stopNumber
          }
          id
          title
        }
        edges {
          node {
            slug
            title
            id
            content
            guideFields {
              stopNumber
            }
          }
        }
      }
    }

    I have added the following code to my functions.php but I seem to be missing something. I based the code of the tutorial I found here. https://www.wpgraphql.com/2020/04/14/query-posts-based-on-advanced-custom-field-values-by-registering-a-custom-where-argument

    add_filter('graphql_post_object_connection_query_args', function ($query_args, $source, $args, $context, $info) {
    
    	$stop_id = $args['where']['stop_number'];
    
    	if (isset($stop_id)) {
    
    		$query_args['meta_query'] = [
    				[
    					
    						'key' => 'stop_number',
    						'value' => $stop_id,
    						'compare' => '='
    				]
    		];
    }
    	
    
    	return $query_args;
    }, 10, 5);
Viewing 1 replies (of 1 total)
  • Plugin Contributor David Levine

    (@justlevine)

    Hey @fograinfall,

    Since the PostObjectConnectionResolver uses a WP_Query() behind the scene, the easiest way to debug this would be to pass those filtered $query_args to a new WP_Query() call and compare the results. If your own query is also coming back bad, then inspect those args to see what’s going wrong.

    If the manual query comes back valid, then it’s likely something else in your stack (custom code, 3rd party plugin, etc) modifying the query. In that case you can go the tried and true “disable, then reenable your plugins one by one” or enable SQL query logging in the WPGraphQL Settings to see what’s actually being requested in order to help you narrow it down.

Viewing 1 replies (of 1 total)
  • The topic ‘Filter by ACF Field’ is closed to new replies.