• Dear bcworkz,

    The following “wp_redirect” i found in my function.php

    <?php
    add_action(‘template_redirect’, ‘bwp_template_redirect’);
    function bwp_template_redirect()
    {
    if (is_author())
    {
    wp_redirect( home_url() ); exit;
    }
    }
    
    function author_archive_redirect() {
       if( is_author() ) {
           wp_redirect( home_url(), 301 );
           exit;
       }
    }
    add_action( 'template_redirect', 'author_archive_redirect' );
    
    /*remove wordpress version number from front-end pages*/
    function remove_version_from_mysite() {
      return '';
    }
    add_filter('the_generator','remove_version_from_mysite');
    add_filter('generator','remove_version_from_mysite');
    ?>
    // go to region home page if a home page request from same site
    // region determined from referrer URL
    add_action('init', 'tg_home_by_region');
    function tg_home_by_region( $query ) {
      if ( array_key_exists('HTTP_REFERER', $_SERVER ) && 0 === strpos( $_SERVER['HTTP_REFERER'], site_url('/'))) {
        $explode = explode('/', $_SERVER['HTTP_REFERER']);
        $region = $explode[3];
        if ( "/$region/" != $_SERVER['REQUEST_URI'] && '/' == $_SERVER['REQUEST_URI']) {
          wp_redirect( site_url("/$region/"));
          exit;
        }
      }
    }

    the following is in my htaccess file

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^*****/?$ /wp-login.php [QSA,L]
    RewriteRule ^*****/register/?$ /wp-login.php?action=register [QSA,L]
    RewriteRule ^*****/lostpassword/?$ /wp-login.php?action=lostpassword [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    RewriteCond %{REQUEST_URI} !^/wp-content/plugins/file/to/exclude\.php
    RewriteCond %{REQUEST_URI} !^/wp-content/plugins/directory/to/exclude/
    RewriteRule wp-content/plugins/(.*\.php)$ - [R=404,L]
    RewriteCond %{REQUEST_URI} !^/wp-content/themes/file/to/exclude\.php
    RewriteCond %{REQUEST_URI} !^/wp-content/themes/directory/to/exclude/
    RewriteRule wp-content/themes/(.*\.php)$ - [R=404,L]
Viewing 15 replies - 1 through 15 (of 32 total)
  • Moderator bcworkz

    (@bcworkz)

    It occurs to me this topic might be confusing to anyone else dropping in. For such people, this is a continuation of a thread closed due to forum software migration: https://wordpress.org/support/topic/search-result-based-on-menu-category?replies=153

    Taro,
    Hmmm. None of that looks like it could be the cause. The first only applies when is_author() is true, which should only be permalinks containing an author login name. The second you already tested by commenting out add_action('init', 'tg_home_by_region'); and that had no effect. You might try commenting out the author related add_action() lines for good measure. I’d be really surprised if that makes a difference.

    The first .htaccess only applies to specific URLs or is the standard WP rewrite, so that can’t be it either. The last one would manifest itself in a 404 page, so that could not be it either. If you would like to test for good measure, .htaccess lines are commented out with a hash # as the first character of a line. Commenting out RewriteRules will stop that rule form being applied. Do not comment out RewriteRule . /index.php [L], that’s how WP handles permalinks!

    I’m sorry, but I’m pretty much out of ideas. All I can tell you is something is causing a 301 redirect of single posts back to the exact same post, causing an infinite loop.

    Thread Starter Taro

    (@sicktb)

    ok im not going to explain what i did but it should be fixed 🙂

    Moderator bcworkz

    (@bcworkz)

    No problem, it apparently had nothing to do with my part of this.

    The following should correct the appearance of the region-search pagination links. In the function declaration of tg_custom_query_nav(), replace the last part of it from // output links on down with this:

        // output links
        echo "\n<div class=\"paging-navigation\"><div class=\"nav-links\">";
        $link = remove_query_arg('region_page');
        $next .= '<i class="fa fa-chevron-right" aria-hidden="true"></i>';
        $nxt_link = esc_url( add_query_arg('region_page', $s_page+1, $link ));
        if ( $ct_next ) echo "\n<a class=\"nav-next\" href=\"$nxt_link\">$next</a>";
        $prev = '<i class="fa fa-chevron-left" aria-hidden="true"></i>'. $prev;
        $prv_link = esc_url( add_query_arg('region_page', $s_page-1, $link ));
        if ( $ct_prev ) echo "\n<a class=\"nav-previous\" href=\"$prv_link\">$prev</a>\n";
        echo "</div></div>\n";
    }

    Let’s go over the various other elements that were problematic.
    It’s hard for me to tell, are the posts that show up for sample and region-search correct?
    Does the intro breadcrumb go where it’s supposed to go?
    Is the correct menu being output on sample and region-search?
    Is the login page going where it should?

    I noticed there is no sidebar content on sample. Is this a coding issue or has it just not been setup yet?

    Anything else?

    Thread Starter Taro

    (@sicktb)

    For Benelux and Worldwide the posts that are displayed are correct. The search works on the region aswel.

    The “intro” breadcrumb should redirect to domain.com/ now its redirecting to domain.com/region.

    The menu is correct for both regions

    The login is not redirecting to the correct page. It just loads the login page again. But login works.

    I’m not sure if other things like tags etc work correct.

    Moderator bcworkz

    (@bcworkz)

    To stop the intro redirect just comment out the add_action('init', 'tg_home_by_region'); line in functions.php. At one time you wanted homepage requests like domain.com/ to go to the regional home if the link was from a regional page. Without that code all domain.com/ links will go to the site home page.

    The login redirect, if you mean wp-login.php, that would have to be an .htaccess rule because file redirects occur before WP is even initialized. You can comment out .htaccess lines to test by placing a hash # in front of the suspect line.

    Thread Starter Taro

    (@sicktb)

    i did remove add_action(‘init’, ‘tg_home_by_region’); and domain.com/ and wp-login works again.

    domain.com/benelux?category_name=benelux
    domain.com/benelux?category_name=benelux-news
    domain.com/benelux?tag=watch
    domain.com/benelux?tag=takeoff
    domain.com/benelux?tag=ready

    The above are not linking correct. Thy go to the region homepage…

    Moderator bcworkz

    (@bcworkz)

    Let’s try adding the following code just after function tg_set_region( $query ) { in functions.php:

    //--------debug-----------
    if ( !is_admin() && $query->is_main_query())
       print_r( $query );
    //------------------------

    This should dump a bunch of debug text at the top of every page. Post a reply here once it’s in place and I’ll see if I can track down the problem. If you instead get a “headers already sent” or other such error, remove that debug code again and let me know what error message appeared. IIRC you have WP_DEBUG defined as true in wp-config.php. This needs to be the case or you’ll just see a blank screen instead of an error message.

    Thread Starter Taro

    (@sicktb)

    intro page
    WP_Query Object ( [query] => Array ( ) [query_vars] => Array ( [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 2580 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [title] => [fields] => [menu_order] => [embed] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [post_name__in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND [table_aliases:protected] => Array ( ) [queried_terms] => Array ( ) [primary_table] => [primary_id_column] => ) [meta_query] => [date_query] => [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => 1 [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_embed] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => 1 [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash:WP_Query:private] => f218c945855497c7b85b948ea929583f [query_vars_changed:WP_Query:private] => [thumbnails_cached] => [stopwords:WP_Query:private] => [compat_fields:WP_Query:private] => Array ( [0] => query_vars_hash [1] => query_vars_changed ) [compat_methods:WP_Query:private] => Array ( [0] => init_query_flags [1] => parse_tax_query ) )

    sample page
    WP_Query Object ( [query] => Array ( [page] => [pagename] => benelux/sample ) [query_vars] => Array ( [page] => [pagename] => benelux/sample [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [title] => [fields] => [menu_order] => [embed] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [post_name__in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) ) [tax_query] => [meta_query] => [date_query] => [queried_object] => WP_Post Object ( [ID] => 10781 [post_author] => 1 [post_date] => 2016-04-11 11:59:39 [post_date_gmt] => 2016-04-11 11:59:39 [post_content] => [post_title] => sample [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => sample [to_ping] => [pinged] => [post_modified] => 2016-07-07 14:31:02 [post_modified_gmt] => 2016-07-07 12:31:02 [post_content_filtered] => [post_parent] => 11240 [guid] => http://domain.com/?page_id=10781 [menu_order] => 0 [post_type] => page [post_mime_type] => [comment_count] => 0 [filter] => raw ) [queried_object_id] => 10781 [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => 1 [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_embed] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => 1 [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash:WP_Query:private] => 1fff3aecd45700c27bc5058ee5cdca24 [query_vars_changed:WP_Query:private] => [thumbnails_cached] => [stopwords:WP_Query:private] => [compat_fields:WP_Query:private] => Array ( [0] => query_vars_hash [1] => query_vars_changed ) [compat_methods:WP_Query:private] => Array ( [0] => init_query_flags [1] => parse_tax_query ) )

    needed to post it here. Website is live for others.

    • This reply was modified 7 years, 7 months ago by Taro.
    Moderator bcworkz

    (@bcworkz)

    Ah, I didn’t know it’s a production site, I thought it was a staging site. I had planned to view the page source, the data dump is much easier to read there. I also need the dumps for a tag and category request please, like those in your post before last. When using your browser’s source view to copy from, you probably should use pastebin.com to post the output since it ends up being quite long.

    Thread Starter Taro

    (@sicktb)

    paste bin for tag and category http://pastebin.com/cG0yVtL5

    • This reply was modified 7 years, 7 months ago by Taro.
    Moderator bcworkz

    (@bcworkz)

    Thanks for doing that. I now know what’s happening, unfortunately, I’m not sure how to fix it. When we request something like domain.com/benelux/?tag=ready, the parser thinks you want the page “Benelux” instead of an archive of regional posts tagged “ready”. It then sets the pagename query var to “benelux” and once that’s done, nothing else in the request matters, you’re going to get that Benelux page.

    My best suggestion is to change the region home page slugs to something that doesn’t match any category or tag, like benelux-home and worldwide-home. Hopefully that’ll result in an archive page instead of home page.

    Thread Starter Taro

    (@sicktb)

    I found a menu bug :(. Page 1 is normal but page 2 uses a diffrent menu.

    http://domain.com/benelux/clic-by-suzanne/images/nggallery/page/2

    login: clic089

    Thread Starter Taro

    (@sicktb)

    I removed the category benelux and worldwide from the posts and pages. Changed it to benelux-news and worldwide-news. The menu and page layout is still the same and the taxonomy location(region) is still active on the posts and pages (benelux and worldwide).

    But its not realy working: http://domain.com/edox?category_name=edox?category_name=edox

    If you look at the newspage: you can see the correct path: http://domain.com/benelux/news but the breadcrumbs are incorrect Intro » Benelux-News. This should be

    Intro » Benelux » Benelux-News

    • This reply was modified 7 years, 7 months ago by Taro.
    • This reply was modified 7 years, 7 months ago by Taro.
    Moderator bcworkz

    (@bcworkz)

    Yeah, removing the category would not be the solution, that is needed to get to the right version of regional pages like “sample”. That was not my intention. Please restore the category.

    It appeared from the data dumps that the Benelux home page slug was “benelux” and I thought that was the problem name, not the category term “benelux”. Is the Benelux home page slug then not “benelux”? Then what is the Benelux home page slug? Something with “benelux” as a part? If not, I need to rethink what’s happening here, otherwise try removing any mention of benelux from the slug.

    Apologies for the confusion.

    Thread Starter Taro

    (@sicktb)

    If i change the slug the permalinks will be changed..?

    I will get the following: http://www.domain.com/benelux-home/sample

    Is it possible to change the regional page to “benelux-news”?

Viewing 15 replies - 1 through 15 (of 32 total)
  • The topic ‘Re: Search result based on menu category’ is closed to new replies.