1

I have a custom WordPress plugin built for booking courses etc.

My custom plugin has some new tables in which custom data like slot date, time etc are stored.

I am trying to modify archive query for courses so it is ordered by slot date from another table so i am using posts_join hook to LEFT JOIN my courses table with posts table and then posts_orderby to order results by slot_date

I want to run this only on my courses archive page but it seems to be running everywhere across the site.

So i used an if statement witin posts_join hook to filter by post type but the site gives a critical error saying Memory exhausted.

Am i doing something wrong?

add_filter( 'posts_join', 'add_other_table', 10, 2 );

function add_other_table( $join, $wp_query ) {
if ($wp_query->query_vars['post_type'] == 'courses') {
 global $wpdb;
$join .= " INNER JOIN {$wpdb->prefix}course_slots as courseslots on courseslots.post_id = $wpdb->posts.ID";
 return $join;
}
}

add_filter( 'posts_where', 'ss_where_table', 10, 2 );

function ss_where_table( $where, $wp_query ) {
if ($wp_query->query_vars['post_type'] == 'courses') {
 global $wpdb;
 $where .= $wpdb->prepare( " AND courseslots.post_id=$wpdb->posts.ID" );
 return $where;
}
}
1
  • Did you find a solution?
    – marek.m
    Commented Jul 7, 2022 at 12:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.