Support » Fixing WordPress » Ajax search for custom post type

  • Hello,

    I have added URL with a query string like that /?facility-name=Oftalmol%C3%B3gia&s=14&facility-region=Vyberte+krajinu&search-type=clinic
    But I want to add like /nameOfCustomPostType/clinic category name/region-category name/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz


    I don’t see how Ajax fits into this. All Ajax requests in WP must go through /wp-admin/admin-ajax.php. Maybe Ajax is the wrong term?

    In any case, to get an URL structure like you want, you would use add_rewrite_rule(). When creating rules, unless you have a predictable, constant element for the regexp to partially match against, it’s difficult to come up with a rule that does not conflict with other rules. For example, add “search” to the URL: The regexp can always match “search” no matter what else happens afterwards.

    If the post type doesn’t change, you could instead match an alias as the post type for regexp purposes, then pass the actual post type in the rewrite. For example, if the post type were “clinic”, an alias could be “health-care” so the URL could be, which would be rewritten to

    Hi bcworkz,

    can you have an example and reference link provide me.

    Moderator bcworkz


    See the add_rewrite_rule() link in my previous reply. There are examples near the bottom. After adding a rule, be sure to visit the permalinks settings screen. No need to change anything, but loading the screen causes the rules to be regenerated.

    Hey @bcworkz,

    Thanks for your quick reply.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Ajax search for custom post type’ is closed to new replies.