url rewriting - How can I re-query post_type and rewrite the url?

admin2025-04-19  0

I have the url slush like the below.

/category/land-residential-farm/?property_com_listing_type=sale

I want to write the url to

/category/land-residential-farm/property-for-sale

then re-query the post for sale meta data.

Anyone please kindly point the way

I have the url slush like the below.

/category/land-residential-farm/?property_com_listing_type=sale

I want to write the url to

/category/land-residential-farm/property-for-sale

then re-query the post for sale meta data.

Anyone please kindly point the way

Share Improve this question asked Oct 24, 2019 at 6:17 Kimsea SokKimsea Sok 171 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I think you need to first define property_com_listing_type as a query:

  • https://codepen.io/the_ruther4d/post/custom-query-string-vars-in-wordpress

Then you can rewrite the urls with add_rewrite_rule (do not forget to save permalinks after change):

  • https://codex.wordpress/Rewrite_API/add_rewrite_rule

with a regex like ^category/([^/]+)/([^/]+)/?

Then you can modify the query using pre_get_posts:

  • https://developer.wordpress/reference/hooks/pre_get_posts/
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745057489a282489.html

最新回复(0)