Taro
Forum Replies Created
-
Forum: Hacks
In reply to: Search result based on menu categorySorry for late replay: i made the change
<?php // add region category to main queries add_action('pre_get_posts', 'tg_set_region'); function tg_set_region( $query ) { if ( get_option('page_on_front') == $query->get('page_id')) return; if ( !is_admin() && $query->is_main_query()) { global $region; $explode = explode('/', $_SERVER['REQUEST_URI']); $cat = $query->get('category_name'); $region = $explode[1]; if ( '' != $cat ) $cat .= '+' . $region; else $cat = $region; $query->set('category_name', $cat); } } // 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'); // deze had ik er uit gehaald 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; } } } // alter category and tag links to be compatible with global $region category // add_filter('term_link', 'tg_alter_term_links', 999, 3 ); // deze heb ik er nu uit gehaald function tg_alter_term_links( $termlink, $term, $taxonomy ) { global $region; if ('category' == $taxonomy ) { $termlink = site_url('/') . $region . '?category_name=' . $term->slug; } if ('post_tag' == $taxonomy ) { $termlink = site_url('/') . $region . '?tag=' . $term->slug; } return $termlink; } /** * Outputs prev/next nav links for custom query pages * * @param array, $args, the same $args used for the page's main WP_Query * The args array must include an 'offset' argument, relying on 'paged' will not work. * string, $next, text for next page link (optional) default "Older Posts" * string, $prev, text for previous page link (optional) default "Newer Posts" * @return none, outputs prev/next nav links with region_page URL parm inside a div with * class 'search_page_nav', anchor links have class 'search_page_next' and 'search_page_prev' * @globals $_GET['region_page'], used to determine current page number. Page 1 assumed * if 'region_page' is not set. */ function tg_custom_query_nav( $args, $next = 'Older Posts', $prev = 'Newer Posts' ) { // determine pagination parms $s_page = isset( $_GET['region_page']) ? sanitize_text_field( $_GET['region_page']) : 1; $pppage = isset( $args['posts_per_page']) ? $args['posts_per_page'] : get_option('posts_per_page'); if ( -1 == $pppage ) return; $prev_off = ( $s_page - 2 ) * $pppage; $next_off = $s_page * $pppage; // 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; // output links echo "\n<div class=\"search_page_nav\">"; $link = remove_query_arg('region_page'); $nxt_link = esc_url( add_query_arg('region_page', $s_page+1, $link )); if ( $ct_next ) echo "\n<a class=\"search_page_next\" href=\"$nxt_link\">$next</a>"; $prv_link = esc_url( add_query_arg('region_page', $s_page-1, $link )); if ( $ct_prev ) echo "\n<a class=\"search_page_prev\" href=\"$prv_link\">$prev</a>\n"; echo "</div>\n"; } ?>
Forum: Reviews
In reply to: [SimpleMap Store Locator] Plugin still works like a charmHi Michael, Its already beter than some months ago.
I big plus would be the search in the admin. It can only search for Title. It would be nice to search for (at least) address, city and country. I wouldn’t mind if it can search in all fields (maybe a selector would be a option).
I also used the following function with plugin “Admin columns”
add_filter( ‘manage_edit-post_sortable_columns’, ‘my_sortable_post_column’ );
function my_sortable_post_column( $columns ) {
$columns[‘column-taxonomy’] = ‘column-taxonomy’;
$columns[‘column-meta’] = ‘column-meta’;//To make a column ‘un-sortable’ remove it from the array
//unset($columns[‘date’]);return $columns;
}Forum: Hacks
In reply to: Search result based on menu categoryThe url still has the region when i remove ‘pre_get_posts’ the only thing that will be removed is the menu where we use $region.
If the original URL without the ‘pre_get_posts’ action can be made to have the region in it again, like it was originally, then all the other elements will fall into place. I don’t know how that was accomplished
Rather easy: I made a page called “benelux” and “worldwide” and linked all pages to these pages.
Forum: Hacks
In reply to: Search result based on menu categoryWhen i remove
add_action('pre_get_posts', 'tg_set_region');
the menu will not use the'menu' => $region,
it will get the basic menu. And the basic menu is showing home and worldwide at the moment. I did not configure the basic menu.I removed the comment out
add_action('pre_get_posts', 'tg_set_region');
so the menu is working again.Forum: Hacks
In reply to: Search result based on menu categoryi wouldn’t call it a fix ?? it did remove the region in total…
Forum: Hacks
In reply to: Search result based on menu categoryThat fixed the login problem. Did not fix the riderect to “worldwide/region-search”.
Forum: Hacks
In reply to: Search result based on menu categorythe only redirect in the htacces is for the custom login page.
I had some problems when i tryed to login. I can login to the admin but the wp-login screen did not return me to the homepage.I removed your function code and it did work again. There is a problem with the function code…
Forum: Hacks
In reply to: Search result based on menu categoryThe search works!
I cant’t find a 301 redirect with sample or region in the name… Both benelux en worldwide pages are online with the a template.
Forum: Hacks
In reply to: Search result based on menu categoryI did add the line. When i search for “basel” i get no result. The permalink also changes to ‘worldwide’ when it should be ‘benelux.’
<?php if ( $the_query->have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
Forum: Hacks
In reply to: Search result based on menu categoryI think i misunderstood your reply and removed the $args = array on the posts template. But i think you wanted me to replace it on the region-search.php.
I changed back the posts format on the test-page.php(benelux/sample).
So now i replaced the following on the region-search.php
<?php $args = array( 'category_name' => $_GET['category_name'], 'posts_per_page'=> 6, 's' => $_GET['term'], ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : ?>
for
if ( isset( $_GET['region_page'])) $s_page = $_GET['region_page']; else $s_page = 1; $search = sanitize_text_field( $_GET['region_search']); $pppage = 6; $args = array( 's' => $search, 'category_name' => $region, 'posts_per_page'=> $pppage, 'offset'=> ( $s_page - 1) * $pppage, ); if ( 1 != $s_page ) { $args['ignore_sticky_posts'] = true; // stickies only on 1st page $args['post__not_in'] = get_option('sticky_posts'); }
I got a error on line 63 and 67
Forum: Hacks
In reply to: Search result based on menu categoryOk im back again, lots of work made; some changed to the website and i needed to secure the website(all known logins are removed)
I made all the new code changes i have put it on the benelux/sample page. The following code is now placed on the test page
Forum: Hacks
In reply to: Search result based on menu categoryI didn’t have time to test the code yet. I changed the post page to benelux/news
Not sure if this is a problem for the code…
Forum: Hacks
In reply to: Search result based on menu categoryThat would be because the query args do not account for pagination. Did you place that on archive.php? The template that I assume is used for domain.com/benelux/? If so, the only added code from the theme default should be global $region;
I did not add it on archive.php. I made a custom page template with header for this page. See here the code for header and page on domain/benelux/
I will change the code on Sunday. Ill try to get all the options on the sample page(s).
Forum: Hacks
In reply to: Search result based on menu categoryTryed that code but the pagination will not load the correct posts. It loads the same 6 posts again domain.com/benelux/page/2
Forum: Hacks
In reply to: Search result based on menu categoryThe following link (logo link) redirects to the first page. But i like it to redirects to the current home region page… Is this posible? I know i can put ‘/benelux’ but this is for the standaard header.php
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">