• Hi all,

    long story short:
    i need a custom parametrized post search, whose results should be rendered with the current theme’s archive template

    short story long :
    i need to display an archive page with a very simple form above.
    when user edits form fields , a custom query should be triggered, and the archive page should refresh with the posts from the query results.
    The custom query is not a problem for me..
    I can’t find a solution for:
    – Rendering, in a post/page, the current theme’s archive (with the current theme’s template!)
    or alternatively
    – prepend to an archive page the form
    and override the standard query with custom query i made

    Any suggestion is appreciated !

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Any particular theme could have any number of archive templates. You need a hook that fires on all templates, then use the is_archive() template tag to decide whether to do anything or not. A good hook should be the ‘loop_start’ action.

    To get the same page with a new query, set the form action to the current request in $_SERVER. The form values will be added as URL parameters, assuming your form is using GET method.

    Which hook you use to alter the new query depends on how you need to change the query. If you can get the right query by setting query vars, use ‘pre_get_posts’ action. There’s also a number of filters for altering various clauses in the query, such as ‘posts_where_paged’ for the WHERE clause. There is also ‘posts_request’ to alter the entire query at one time.

Viewing 1 replies (of 1 total)
  • The topic ‘custom parametrized archive search’ is closed to new replies.