• Hi All,

    i’m looking for two pieces of code that can help me with the following:

    I got posts and pages with a custom menu. These posts/pages got a custom template activated. The templates contains the menu for the specific posts and pages. This way i can order pages/posts in two different categories.

    Now i like to change the search function; the search output should be based on the active custom menu category.

    I named menu 1: Benelux and menu 2: International

    1: First peace of code needs to be for the searchform.php
    The code should look at the current active menu(category) and the search result should be based on the active menu.

    If the menu is for example “Benelux” then the search result should only display pages/posts from the custom taxonomy that i made <input type=”hidden” name=”location” value=”benelux” />
    Or if the active menu is “International” then display pages/posts from the custom taxonomy <input type=”hidden” name=”location” value=”international” />

    I found the following code to get the menu category…not sure if this is useful..

    (wp_nav_menu( array(
        'menu' => 'benelux'
    ) )

    2: Second peace of code is needed for the search.php (header).
    Because if the output should work correctly than we also need to change the menu for this search result page. Default the search.php uses the main menu.

    So the following code needs to see if the pages/post contain taxonomy benelux or international and change the menu accordingly.

    It would just be really awesome if this is possible.

    Greatings,
    Taro

Viewing 2 replies - 151 through 152 (of 152 total)
  • Thread Starter Taro

    (@sicktb)

    removing the following did not work…

    add_action(‘pre_get_posts’, ‘tg_set_region’);
    add_action(‘init’, ‘tg_home_by_region’);
    add_filter(‘term_link’, ‘tg_alter_term_links’, 999, 3 );

    maybe below:

    // check for more posts
    	$args['no_found_posts'] = true;		// just get a count
    	$args['ignore_sticky_posts'] = true;
    	$args['offset'] = $next_off;
    	$query = new WP_Query( $args );		// get next page post count
    	$ct_next = $query->post_count;
    	$args['offset'] = $prev_off;
    	$query = new WP_Query( $args );		// get prev page post count
    	$ct_prev = 1 < $s_page ? $query->post_count : 0;
    Moderator bcworkz

    (@bcworkz)

    Good thought, but no, that just generates the pagination links. The problem occurs after clicking one of the read more links, after which the pagination code has nothing to do with what’s happening. I thought it might have to do with the function called by add_action('init', 'tg_home_by_region'); because it has a wp_redirect() in it. Since the problem persists without that line, it has to be something else.

    Any code using wp_redirect() might be a factor, as might any added rewrite rules. It might even be an .htaccess rule. It appears to be unrelated to sample or region-search pages, since both example.com/benelux/junghans-launch-event and example.com/worldwide/junghans-launch-event typed into the browser both do not redirect properly. Curiously, just example.com/junghans-launch-event (no region specified) results in a post not found page, yet we know it exists because it shows up in sample and region-search listings. It seems like it might be a meaningful distinction, but I’m not sure what it means. Also, entering simply example.com/?p=10849 (the post’s ID) results in a redirect error as well after it is first rewritten to example.com/benelux/junghans-launch-event, so we know the post is being found in order to do the initial rewrite. Very strange!

    Try going to the permalink settings page and clicking save changes without changing anything. This can sometimes fix errant rewrite rules.

    You might try deactivating all plugins to see if that changes anything. If it does, reactivate each plugin one by one. When the problem recurs, the last activated plugin is the problem. If the problem persists without any plugins, try switching to a twenty* theme for a bit. If the problem still persists with a simple example.com/?p=10849, there is a fundamental flaw in your installation. Re-installation may be in order. I expect it to work in the default state, which indicates the problem is with your theme, probably a customization somewhere.

    Switch back to your usual theme. All I can suggest after all of that is to selectively comment out sections of code until you find something that fixes the problem. If you find anything, post the segment here, maybe I can determine a more permanent fix or workaround.

Viewing 2 replies - 151 through 152 (of 152 total)
  • The topic ‘Search result based on menu category’ is closed to new replies.