Support

Account

Home Forums General Issues Post Object meta query

Helping

Post Object meta query

  • Hello,

    i have a custom post type that has a post object custom field and in the {cpt}-single.php i want to find this custom post types with the following query:

    ` $query = new WP_Query(array(
    “post_type” => “mycustomposttype”,
    “meta_query” => array(
    ‘key’ => ‘my_custom_field’,
    ‘value’ => ‘”‘ . get_the_ID() . ‘”‘,
    ‘compare’ => ‘LIKE’
    )
    ));`

    but this does not work the filter has no effect i get everytime all posts… i already checked if the get_the_ID() value is correct and yes it is.

  • Hi @mathishuettl

    Could you please share the JSON or XML export field of your field group?

    Also, could you please check if the Select multiple values? is set to “Yes” or “No”?

    If it’s set to “No”, then you need to query it like this:

    $query = new WP_Query(array(
        "post_type" => "mycustomposttype",
        "meta_query" => array(
            'key' => 'my_custom_field',
            'value' => get_the_ID()
        )
    ));

    Thanks 🙂

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

The topic ‘Post Object meta query’ is closed to new replies.