Relationship – sort order
-
(the password for the staging site is $t@g!ng) (Ignore the quality of the image. Ignore the weird icons.) (staging site will be gone after deploy to production ; if you’re here after that happens you won’t see the staging site live))
I have a custom post type created in Pods, called Dogs. within that I have a bi-directional relationship to another custom post type, called Distinctions.
I’m able to display the Dog, grab the related Distinctions. Yay.
Now, how do I SORT the Distinctions by a particular field? In my case I want to sort by it’s name so distinctions.Distinction-name.
Here’s how I’m parsing the data.
$distinctions = $dogs->field( 'distinctions' ); // would like to get this SORTED if (! empty ($distinctions) ) { foreach ( $distinctions as $distEarned ) { $distID = $distEarned[ 'ID' ]; $distName = get_post_meta( $distID, 'distinction-name', true ); $distDesc = get_post_meta( $distID, 'description', true ); $distDesc = str_replace('<p>', '', $distDesc); $distDesc = str_replace('</p>', '', $distDesc); $useClass = 'dog-dist-' . str_replace(' ', '-', strtolower($distName)); $useText = $distName; if ($distName === 'Champion') { $useText = 'Conformation Champion'; } $thisDistinctionIcon = '<span class="' . $useClass . '" alt="' . $useText . '" title="' . $distDesc .'"></span>'; $distinctionsEarnedText = $distinctionsEarnedText . '<tr><td>' . $thisDistinctionIcon . '</td><td>' . $useText . '</td><td>' . $distDesc . '</td></tr>'; $distinctionsEarnedIcons = $distinctionsEarnedIcons . $thisDistinctionIcon; } }
The page I need help with: [log in to see the link]
- The topic ‘Relationship – sort order’ is closed to new replies.