Redirect Expired Events
This topic contains 5 replies, has 2 voices, and was last updated by Kiran 6 years, 10 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: expired events, Redirect
-
AuthorPosts
-
May 16, 2018 at 10:31 am #430811
Good day,
I am hoping you can assist in improving my 404 pages generated from expired events.
I am trying to create a function that will redirect expired events in a particular category (that will usually display a 404 page) to the root category. i am using multi-city and my redirect action is not working.
I have the following code:
// Expired Events Redirect add_action( 'template_redirect', 'expired_events_redirect' ); function expired_events_redirect() { // check if is a 404 error, and custom post type events and category if( is_404() && is_singular('gd_event') && is_category( 'festival' ) ) // if( is_404() && is_singular('your-job-custom-post-type') ) { // then redirect to wp_redirect( home_url( '/events/festival/' ) ); exit(); } }
Do you think this is possible. Am I missing something.
You assistance is much appreciated.
Kind regards,
May 16, 2018 at 12:55 pm #430844Hi,
Try this one:
function expired_events_redirect_setup( $post, $query ) { global $wp, $gd_expired, $wp_query; if ( !empty( $post ) && !empty( $query->is_single ) && $post[0]->post_type == 'gd_event' ) { $check_is_expired = false; // DO STUFF HERE TO CHECK HERE EXPIRED OR NOT if ( $check_is_expired ) { $gd_expired = $post[0]->ID; $wp_query->is_single = true; } } return $post; } add_filter( 'posts_results', 'expired_events_redirect_setup', 10, 2 ); function expired_events_redirect() { global $wp, $post, $wp_query, $gd_expired; if ( is_404() && $gd_expired ) { $gd_post = get_post( $gd_expired ); if ( !( !empty( $gd_post ) && $gd_post->post_type == 'gd_event' ) ) { return; } $default_category_id = geodir_get_post_meta( $gd_post->ID, 'default_category', true ); $term = $default_category_id ? get_term( $default_category_id, $gd_post->post_type . 'category' ) : ''; $default_category = !empty( $term ) && !is_wp_error( $term ) ? $term->slug : ''; if ( $default_category ) { $redirect_url = get_term_link( $default_category ); } else { $redirect_url = home_url(); } wp_redirect( $redirect_url ); exit(); } } add_filter( 'template_redirect', 'expired_events_redirect' );
Kiran
May 17, 2018 at 10:50 am #430949Hi Kiran,
Thanks for taking a shot at this.
Your code does not seem to do anything on my site regarding 404’s for Expired/Draft events although I see where you are going with this but unfortunately my PHP skills are lacking in this regard.
I am not sure how events are tagged ‘Expired’ in GD. My site is set to ‘Expired > Draft’ and not ‘Expired > Trash’ although both instances will obviously result in a 404. Not sure if that makes any difference.
Any further input appreciated.
May 17, 2018 at 1:55 pm #430972I just given code with basic logic that you can follow. you have to write code to check event expire or not at “// DO STUFF HERE TO CHECK HERE EXPIRED OR NOT”.
Event can be expired via package or via event date. which one you following?
Kiran
May 17, 2018 at 7:08 pm #431037Hi Kiran,
My events expire via package ‘alive days’.
I was not aware that events could expire when the date of the event passes. Is this a new feature?
Would love to sort out my analytics 404’s though.
Many thanks
May 18, 2018 at 7:04 am #431079Hi Dale,
Use following code to find listing is expired or not. Replace “$check_is_expired = false; // DO STUFF HERE TO CHECK HERE EXPIRED OR NOT” in previous code.
$post_expire_date = geodir_get_post_meta( $post[0]->ID, 'expire_date', true ); $check_is_expired = ( $post_expire_date != '0000-00-00' && $post_expire_date != '' && geodir_strtolower( $post_expire_date ) != 'never' && strtotime( $post_expire_date ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) );
This is customization and it is beyond support, so we can help you more in code customization. You can hire developer from http://geodirectoryexperts.com/
Kiran
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket