Taro on "Search result based on menu category"

ساخت وبلاگ

You don't need to change the 'query_vars' callback name, but it wouldn't hurt. There's no reason a function cannot be named the same as a filter hook name, but I think it's slightly confusing to do so. Others probably think it is more clear, but I rarely see anyone doing it.

Please change the rewrite hook like this:

function custom_select_region() { add_rewrite_rule('^([^/]*)/([^/]*)/?','index.php?pagename=$matches[2]&region=$matches[1]','top'); add_rewrite_rule('^([^/]*)/([^/]*)/([0-9]{1,})/?','index.php?pagename=$matches[2]&region=$matches[1]&paged=$matches[3]','top');
add_action('init', 'custom_select_region', 0 );

I've come to the realization that I've been addressing little details without a good grasp of the overall situation. Time to take a step back and make sure I understand what you're trying to do as a test with the sample page.

I'm assuming you begin the test with requesting your-domain.tld/benelux/sample/

If so, checking for things in $_POST is pointless because we made a GET request. Thus get_posts() would just retu what it does by default, a page's worth of posts regardless of category. It seems to me you should be checking for $_GET['region'] on sample to get posts in the Benelux category, assuming the rewrite rules are working.

If that much works with using $_GET, then going to the next page is the next test. The link should be your-domain.tld/benelux/sample/2/, but I'm not confident that is what the next page link is pointing to. It might be missing the Benelux part.

Regardless of what the next page link is, entering your-domain.tld/benelux/sample/2/ in your browser will hopefully result in the next page of Benelux posts.

I do not see any reason to check for the 's' parameter on the sample page unless the same template is also used for the static front page of your site. (assuming the search form's action is still pointing to your site's home page)

If the front page is using the same template, you should get the region parameter from $_REQUEST['region'] so that either GET or POST requests are covered. There's a slight security issue with $_REQUEST, but it shouldn't be an issue in this context.

Now the search form itself. Does this appear on the sample page? If so, instead of trying to get the region out of the query, see if you can use $_GET['region'](or $_REQUEST['region'] on a front page template). Using the query for region should have worked, but it's more complicated. If $_GET['region'] works, it greatly simplifies things.

On whatever page loads after the form submits is where using $_POST is appropriate, like what you currently have for the sample page. However, if the page can be requested with GET, you need to use $_REQUEST['region']. $_POST['s'] is still OK because search requests will only come in via POST. Only the region parameter needs to work for both.

We will still need to get the query var part working at some point for other templates that use the main query and do not use get_posts(), but let's just focus on getting sample and the search form working first.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 288 تاريخ : جمعه 31 ارديبهشت 1395 ساعت: 21:04