Search code examples
wordpresspostmetadatalistings

Show custom posts listing according to their metadata selection in dropdown


Senario: I have created a custom post for doctors who are divided according to the Continent, Country and State which are provided in their metadata. i.e., doctors are posts.

I am creating an page for searching of the Doctors according to their Continent, Country and State which changes accordingly (Continent ==> Country ==> State).

Requirements: 1). If I select continent then doctors belonging to that continent gets listed also country and state dropdown gets populated accordingly. 2). If I select country(populated from above) then doctors belonging to that country gets listed also state dropdown gets populated accordingly. 3). If I select state(populated from above) then doctors belonging to that state gets listed.

Optional: I want to use ajax on dropdown change event listing gets updated.

Please Help!!!

Any suggestion is also appreciated.

Thanks in advance.


Solution

  • The questions like homework are actually gets less answers than real questions...

    if you have custom posts and you need filter them, you can use query_posts function of wordpress or get_posts... get_posts have args which helps you to query..

    <?php 
    $args = array(
        'posts_per_page'   => 5,
        'offset'           => 0,
        'category'         => '',
        'orderby'          => 'post_date',
        'order'            => 'DESC',
        'include'          => '',
        'exclude'          => '',
        'meta_key'         => 'doctors_country',
        'meta_value'       => 'England',
        'post_type'        => 'doctors',
        'post_status'      => 'publish',
        'suppress_filters' => true );
    
    
     $posts_array = get_posts( $args); 
    ?>
    

    i hope this helps... you can do whatever you want with the array you have... IE: Triggering ajax request etc..

    Solve one step and ask another question for next step..