Support

Account

Home Forums Front-end Issues how can get post filter by select item

Solved

how can get post filter by select item

  • I really like this plug in but I just have one question and hoping someone will help me…

    In admin, I added some custom fields. Most of them is text and one option I have select type… It works like a sub category. For example item names will be:
    CK
    Mango
    Zara
    Gucci
    Nike

    Now i would like to have some tabs like Ck, mango, zara etc so when i click the tabs it will automatically open that paticular page.

    This is very simple if i use wordpress default category but I would like to use this plug in

    Can someone help me to understand how it works

  • Hi @pagol,

    One way to achieve this would be: First, have two pages, one to display the Choices/tabs and the other one to display the posts for a particular chioice/tab.

    On the template for the page that displays the posts, add the following code:

    $value = $_GET['value']; // get value of selected choice.
    $args = array(
        ...
        'meta_key' => '<select_field_name>',
        'meta_value' => $value
    );
    $the_query = new WP_Query( $args );
    ... // display posts

    Where $value will be the value of the selected choice/tab passed through a query string e.g. The CK tab could open this link http://your-domain.com/page-that-displays-posts/?value=CK

    For more info on this, have a look at the following resources:
    Filter posts by custom fields,
    Creating a WP archive with custom field filter

  • thanks for reply. i will and keep update post here. thanksa gain

  • thanks it work fine 🙂 quick and great support

  • i have another issue. how can i print selected select box label on page. say like my url is http://your-domain.com/page-that-displays-posts/?value=CK

    i want to print on page <h1>CK</h1>

    i tried with <h1> <?php echo $value; ?> </h1> i come ok. no problem. but it come CK which is select value. but i want to print label. CK label is CK Sunglass so i want to inside h1 will print selected value lable . is that possible ?

  • Hi @pagol,

    Hmm… you could try passing the label as an argument in you query string too i.e.
    http://your-domain.com/page-that-display-posts/?value=CK&label=CK Sunglasses

    Then grab this value $label = $_GET['label'];

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

The topic ‘how can get post filter by select item’ is closed to new replies.