query_posts join with custom table
-
Hi.
I have table in my DB called wp_bp_wpisy (post_id, group_id, date_added)
I need to get all posts with specific group_id, order this by date_added and I need pagination for this.
I tried like this(found on forum):
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $wpdb->bp_wpisy = $wpdb->prefix . 'bp_wpisy'; function mam_posts_join ($join) { global $mam_global_join; if ($mam_global_join) $join .= " $mam_global_join"; return $join; } function mam_posts_where ($where) { global $mam_global_where; if ($mam_global_where) $where .= " $mam_global_where"; return $where; } function mam_posts_orderby ($orderby) { global $mam_global_orderby; if ($mam_global_orderby) $orderby = $mam_global_orderby; return $orderby; } add_filter('posts_join','mam_posts_join'); add_filter('posts_where','mam_posts_where'); add_filter('posts_orderby','mam_posts_orderby'); $mam_global_join = " JOIN $wpdb->bp_wpisy AS wpisy ON $wpdb->posts.ID = wpisy.post_id "; $mam_global_where = " and wpisy.group_id = 2"; $mam_global_orderby = " wpisy.dodano ASC"; query_posts("paged=$paged"); /$mam_global_join = $mam_global_where = $mam_global_orderby = ''; // Turn off the filters
Can you help me ?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘query_posts join with custom table’ is closed to new replies.