0

Scenario:
I have a custom post type "book" which the archives are displayed in a page "book-list" using custom page template.

Currently,
index.php?post_type=book gets redirected to this /book-list/ page
index.php?post_type=book&s=scifi gets redirected to /book-list/ without search result
/book-list/?s=scifi leads to a 404

What I want:
to add search functionality and result pages with pagination to search custom post type book by using /book-list/?s=scifi&paged=2 or preferably /book-list/search/scifi/page/2/

How do I approach this?

5
  • Can you please share with me a code you have used for that so I can help you. Mar 7, 2019 at 4:10
  • I dont really have a code right now, i have tried using the below, which still leads to a 404. function custom_rewrite_basic() { add_rewrite_rule('^book-list/?s=([^/]*)', 'index.php?post_type=book&s=$matches[1]', 'top'); } add_action('init', 'custom_rewrite_basic', 10, 0);
    – Calvin
    Mar 7, 2019 at 4:27
  • you should have to try like this wordpress.stackexchange.com/a/89945/62026 Mar 7, 2019 at 4:38
  • Thanks for giving me the direction. Let me try this out.
    – Calvin
    Mar 7, 2019 at 4:41
  • Okay try it and let me know either it's working or not as you requested. Mar 7, 2019 at 4:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.