Want to join another table with get_posts() wordpress

I want to join another table with get_posts() method and fetch fields from new table.

I know about add_filter( 'posts_where','calback_function_name').

Read More

Please help me

Related posts

Leave a Reply

2 comments

  1. You will need to use your own query if you are going to start joining tables.

    This is quite simple to do, and you can use WordPress’s methods to use it’s database handler.

    global $wpdb;
    
    $query = '
      SELECT *
      FROM '. $wpdb->posts .' p
      JOIN my_custom_table c ON p.ID = c.ID  
    ';
    
    $results = $wpdb->get_results( $query, OBJECT );
    

    There is lots of information on this in the WPDB WordPress Codex entry.