'Issues with Wordpress ACF relationship
there. I have two custom post types: species and family.
- In species I have this relational field "family_species" that filters by post type "family".
- In family post type I only have one fild (family_name);
--
1 - So I created a new family called "green" and another one called "red"; 2 - I created new 'species' entry called 'alder' (and selected 'green' family) and another one called 'oak" (and selected 'red' family).
I would like to display in a page a list for family (and once you click on the family name, it opens a html summary/detail with the species related to a specific family).
- Green -- Alder
- Red -- Oak
My following code shows the families but something is not working when it comes to show only the species of each family. I've been trying everything for three days, but it's not working. Can someone help me with that? thanks a lot.
'post_type' => 'family',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
);
$my_query = new WP_Query ($my_args);
if( $my_query->have_posts()) : while ( $my_query->have_posts() ) : $my_query->the_post();?>
<div>
<div>
<details>
<summary><h1><?php
$family_name = get_field('family_name');
echo $family_name; ?>></h1><p></p>
</summary>
<?php
$args = array(
'numberposts' => -1,
'post_type'=> 'species',
'meta_query'=> array(
'relation'=> 'AND',
array(
'key'=> 'specie_name',
'value' => '"' . get_the_ID() . '"',
'compare'=> 'LIKE'
),
array(
'key'=> 'family_for_this_specie',
'value' => $family_name,
'type' => '='
)
)
);
// query
$the_queryy = new WP_Query( $args );
?>
<?php if( $the_queryy->have_posts() ): ?>
<ul>
<?php while ( $the_queryy->have_posts() ) : $the_queryy->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); ?>
</details>
</div>
</div>
<?php endwhile; endif;
wp_reset_query();?>
Thank you so much for your attention
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
