WordPress.org

Forums

query_posts join with custom table (5 posts)

  1. _chris_
    Member
    Posted 2 years ago #

    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 ?

  2. Namita
    Member
    Posted 2 years ago #

    Hi,
    Just did search for your query, you can refer to http://wordpress.org/support/topic/left-join-with-query-post?replies=3.
    i hope it will solve your issue.

  3. _chris_
    Member
    Posted 2 years ago #

    as you can see I tried to rewrite that solution on my case but it doesn't work. mayme i have made a mistake and I can't see it

  4. Namita
    Member
    Posted 2 years ago #

    can you please write the same code as per given on that link "http://wordpress.org/support/topic/left-join-with-query-post?replies=3." and replace the your filteration requirement. I have run the same code and working fine for me.

  5. _chris_
    Member
    Posted 2 years ago #

    But code in #1 post is the same as in http://wordpress.org/support/topic/left-join-with-query-post?replies=3 but with my table and values

Topic Closed

This topic has been closed to new replies.

About this Topic