Hi, I have two custom post types ‘Medicines’ and ‘Components’. I created a relationship field to make users choose all the Components that they want to show into the Medicines.
So far so good. I want to use Querying relationship fields to show on every Components post all the Geneesmiddelen that it’s loaded into. Works great! But how can I order my Geneesmiddelen list that shows on each Component post? I used this code but I can’t order it by post/title name ABC/ASC.. Thanks for your help!
<?php
$medicines = get_posts(array(
'post_type' => 'medicines',
'meta_query' => array(
array(
'key' => 'components_of_medicine',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
'orderby' => 'title',
'order' => 'ASC',
)
)
));
?>
<?php if( $medicines ): ?>
<?php foreach( $medicines as $medicine ): ?>
<li>
<a href="<?php echo get_permalink( $medicine->ID ); ?>">
<?php echo get_the_title( $medicine->ID ); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
$medicines = get_posts(array(
'post_type' => 'medicines',
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'components_of_medicine',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
This reply has been marked as private.