Support

Account

Home Forums General Issues Query posts by custom fields Reply To: Query posts by custom fields

  • Hi @renee

    I believe you were talking about the current page slug where it shows the custom post type, right? In this case, I think you can get the current page slug like this:

    global $post;
    $page_slug=$post->post_name;

    After that, you need to convert the page slug to the value you want like this:

    if( $page_slug == "slug1" ){
        $value = "value1";
    }elseif( $page_slug == "slug2" ){
        $value = "value2";
    }else{
        $value = "value3";
    }

    Then you can use it like this:

    array(
        'key' => 'product',
        'value' => $value,
        'compare' => '=',
    ),

    I hope this makes sense 🙂