-
-
Save tommcfarlin/926f78b195f94c93fdc4 to your computer and use it in GitHub Desktop.
[WordPress] An example for how to JOIN two tables using the WordPress API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'posts_join', 'acme_search_submission_join' ); | |
/** | |
* Performs a JOIN on the post and the post meta tables so that we can retrieve results | |
* that also include data stored in the post meta table. | |
* | |
* @param string $join The initial JOIN clause. | |
* @return string $join The clause for joining the post and the post meta tables, if on the search template. | |
*/ | |
function acme_search_submission_join( $join ) { | |
if ( is_admin() || ! is_search() ) { | |
return $join; | |
} | |
global $wpdb; | |
$join .= "JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id "; | |
return $join; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment