• Resolved boldhand

    (@boldhand)


    Hello,
    I need to add a drop down list with author names, when the user selects an author, the posts are filtered to display only the ones related to that author.

    There is a custom field which has the meta-key ‘Author’ and the value entered is the author name.

    I really appreciate any help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Check out this link: http://codex.wordpress.org/Template_Tags/query_posts#Custom_Field_Parameters

    Custom Field Parameters

    Retrieve posts (or Pages) based on a custom field key or value.

    * meta_key=
    * meta_value=
    * meta_compare= – operator to test the meta_value=, default is ‘=’, with other possible values of ‘!=’, ‘>’, ‘>=’, ‘<‘, or ‘<=’

    Returns posts with custom fields matching both a key of ‘color’ AND a value of ‘blue’:

    query_posts('meta_key=color&meta_value=blue');

    Returns posts with a custom field key of ‘color’, regardless of the custom field value:

    query_posts('meta_key=color');

    Returns posts where the custom field value is ‘color’, regardless of the custom field key:

    query_posts('meta_value=color');

    Returns any Page where the custom field value is ‘green’, regardless of the custom field key:

    query_posts('post_type=page&meta_value=green');

    Returns both posts and Pages with a custom field key of ‘color’ where the custom field value IS NOT EQUAL TO ‘blue’:

    query_posts('post_type=any&meta_key=color&meta_compare=!=&meta_value=blue');

    Returns posts with custom field key of ‘miles’ with a custom field value that is LESS THAN OR EQUAL TO 22. Note the value 99 will be considered greater than 100 as the data is stored as strings, not numbers.

    query_posts('meta_key=miles&meta_compare=<=&meta_value=22');

    Thread Starter boldhand

    (@boldhand)

    Thank you monkeymynd for pointing out using the query_posts, but there is still a point that I need to understand.

    does this mean that i need to create a number of pages equal to the number of authors where each page has a different query_posts,
    then make each name in the drop down list point to one of these pages?

    Easiest thing to do is to figure out how to put Template_Tags/wp_list_authors in a dropdown, then WordPress will do everything else for you.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    Author Templates

    Thread Starter boldhand

    (@boldhand)

    Thank you MichaelH for you useful links, but when i mentioned author I didn’t mean the blog others (users), it could be player names, actor names, artist names …, sorry for not being clear.

    While searching i passed by this
    http://wordpress.org/support/topic/197405?replies=3

    the solution here is using $_GET commands to refresh the page with the filtered posts.

    I’m not a PHP expert, so can someone assist with this with slightly more details? thanks a million:)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘filter posts’ is closed to new replies.