This support ticket is created Il y a 6 années et 4 mois. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
You would need to iterate over the found posts using a foreach loop and for each house post you would get its room child posts, for which you can use the function types_child_posts like so:
where $post_id comes from the house posts you are iterating over.
For house posts that do not have 2 child room posts you can remove the post from the results, being careful to update the post_count and found_posts parameters at the same time.
If you try and get stuck let me know and I will see if I can help.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+01:00)
Hi Jesus
You'll need to add some custom code using the API to your site. I have provided a sample of the code you would need to add (to your theme's functions.php file, or using a plugin such as Code Snippets) below, but please note that providing or supporting custom code is outside our support policy, and if you need further help you should consider contacting a developer such as those listed on our contractors page: https://toolset.com/contractors/
function tssupp_two_rooms( $query, $view_settings, $view_id ){
$house_slug = 'house'; // Edit the house post type slug
$room_slug = 'room'; // Edit the room post type slug
if ( $view_id == 25 ) { // Edit ID
$houses = $query->posts;
foreach ($houses as $key => $house) {
// Get the child rooms of this house
$rooms = get_posts( array( 'post_type' => $room_slug, 'meta_key' => '_wpcf_belongs_' . $house_slug . '_id', 'meta_value' => $house->ID, 'numberposts' => -1 ) );
if ( count($rooms) != 2 ) {
// remove from results because does not have 2 rooms
unset( $houses[ $key ] );
}
}
$number_of_posts = count( $houses );
$query->post_count = $number_of_posts;
$query->found_posts = $number_of_posts;
// reindex and update results
$query->posts = array_values( $houses );
}
return $query;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_two_rooms', 101, 3 );
Note that you have to edit the ID of the View, and the slugs of the house and room custom post types.
Ce ticket est maintenant fermé. Si vous êtes un client de Toolset et que vous avez besoin d'aide, veuillez ouvrir un nouveau ticket d'assistance