Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Exclusive search for p2p
<?php
add_action( 'pre_get_posts', 'query_for_recipe_search' );
function query_for_recipe_search( $query ) {
if ( is_recipe_search() && is_main_query() ) {
$ingredients = isset( $_GET["search_ingredients"] ) ? $_GET["search_ingredients"] : NULL;
if ( is_array( $ingredients ) ) {
global $wpdb;
$recipes = $wpdb->get_col( $wpdb->prepare( "SELECT p1.id from wp_posts p1
INNER JOIN wp_p2p p2p on p2p.p2p_from=p1.id
where p2p_to IN (%s)
GROUP BY p1.id
HAVING COUNT(p2p.p2p_to) = %d", join( "','", $ingredients ), count( $ingredients ) ) );
if ( $recipes ) {
$query->query_vars["post__in"] = $recipes;
}
}
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.