Friday, 15 July 2011

php - INNER JOIN skipping key with the same value -



php - INNER JOIN skipping key with the same value -

im trying filter next_post_link , previous_post_link can used on custom post type called filmfremvisning meta_key field date in it. filmfremvisning cpt kind of "events" cpt event posts have expiration date on them. expiration date has next format of yyyymmdd , named dato_for_fremvisningen.

i have custom post status called expired , cronjob gives expired posts status every night.

i have tried these 2 links:

http://wordpress.stackexchange.com/questions/139453/filter-next-post-link-and-previous-post-link-by-meta-key http://return-true.com/2012/04/custom-ordering-for-wordpress-post-link-functions/

and got working quite nice. problem inner bring together skipping posts has same date.

for illustration if have next posts , dates:

event 1 - 20140102 event 2 - 20140105 event 3 - 20140105 event 4 - 20140107

it returns:

event 1 - 20140102 event 2 - 20140105 event 4 - 20140107

the sql statement furture post is:

inner bring together $wpdb->postmeta m on p.id = m.post_id p.post_type = 'filmfremvisning' , p.post_status = 'publish' , m.meta_key = 'dato_for_fremvisningen' , m.meta_value > '$current_filmfremvisning_date' grouping p.id order m.meta_value asc`

the code im using in functions.php downwards below:

function get_adjacent_past_events_join($join) { if(is_singular('filmfremvisning')) { global $wpdb; $new_join = $join."inner bring together $wpdb->postmeta m on p.id = m.post_id "; homecoming $new_join; } homecoming $join; } add_filter('get_previous_post_join', 'get_adjacent_past_events_join'); add_filter('get_next_post_join', 'get_adjacent_past_events_join'); function get_future_filmfremvisnings_where($where) { if(is_singular('filmfremvisning')) { global $wpdb, $post; $id = $post->id; $current_filmfremvisning_date = get_field('dato_for_fremvisningen', $id); $new_where = "where p.post_type = 'filmfremvisning' , p.post_status = 'publish' , m.meta_key = 'dato_for_fremvisningen' , m.meta_value > '$current_filmfremvisning_date'"; homecoming $new_where; } homecoming $where; } add_filter('get_next_post_where', 'get_future_filmfremvisnings_where'); function get_past_filmfremvisnings_where($where) { if(is_singular('filmfremvisning')) { global $wpdb, $post; $id = $post->id; $current_filmfremvisning_date = get_field('dato_for_fremvisningen', $id); $new_where = "where p.post_type = 'filmfremvisning' , p.post_status = 'publish' , m.meta_key = 'dato_for_fremvisningen' , m.meta_value < '$current_filmfremvisning_date'"; homecoming $new_where; } homecoming $where; } add_filter('get_previous_post_where', 'get_past_filmfremvisnings_where'); function get_prev_past_filmfremvisnings_sort($sort) { if(is_singular('filmfremvisning')) { global $wpdb; $new_sort = " grouping p.id order m.meta_value desc"; homecoming $new_sort; } homecoming $sort; } add_filter('get_previous_post_sort', 'get_prev_past_filmfremvisnings_sort'); function get_next_future_filmfremvisnings_sort($sort) { if(is_singular('filmfremvisning')) { global $wpdb; $new_sort = " grouping p.id order m.meta_value asc"; homecoming $new_sort; } homecoming $sort; } add_filter('get_next_post_sort', 'get_next_future_filmfremvisnings_sort');

php mysql sql wordpress

No comments:

Post a Comment