This is my table:
Name: customTable
Fields: ID | title | date | content | url
and now I want to “inner join” this table into the the normal WP-Query, but only when I am in the category “news”.
This is what I have
function meta_filter_posts( $query )
{
if(is_category('news'))
{
// and here I want to add my custom table (like inner join)
// sorted by date
$query->set('orderby','date');
$query->set('order', 'DESC');
/* innerJoin the table customTable */
}
}
add_filter( 'pre_get_posts', 'meta_filter_posts' );
Any ideas how to include this table? Thanks in advance!
I recommend the answer found here:
https://stackoverflow.com/a/19547093/1361532
This should allow you to purely use WP_Query and its set functions to get exactly what you need to, instead of trying to rebuild the WP_Query object. The only other way I can think to make this work would be a pure query on the database which would seem to be too excessive.