0

I would like to display the wordpress search results on a page which I've created in the wordpress backend. I need a page, because I've custom content on this page which should be changed by backend users. So I can't just use the search.php file.

I've created a page in the backend and assigned a template with all needed code to display the results of a search, but the question is, how to target the searchform to this page.

With this code:

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">

The searchform is using the search.php file to display the results.

Is there any way to use an id in the action parameter or something like that?

Thanks for your help!

  • replace home_url( '/' ) with home_url( '/your-page' ) – karpstrucking Jan 16 '15 at 16:24
  • Did the answer posted here help you? If so please do accept it to help keep the site tidy. – Andy Macaulay-Brook Aug 7 '16 at 14:03
1

I noticed that your goal is to have an editable content on the search result. You can use another method to do that, by calling the content of the page from your search.php file.

You can start by creating a page with the slug search-page as usual. You can also add post meta / custom fields as you need.

And now you can start editing the search.php. Inside the search.php get the page content by using

$page = get_posts(
    array(
        'name'      => 'search-page',
        'post_type' => 'page'
    )
);

Then use the page data inside the $page object in your template. If you need the page meta (custom fields), just use the get_post_meta() functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.