Loop through them with [each related]{@ID}[/each]
That will get you the ID’s individually. What are you wanting to send those ID’s into, however?
Thread Starter
alexnn
(@alexnn)
Yes, these IDs then I want to use in the code and “AND” prevents it
Thread Starter
alexnn
(@alexnn)
Hello Jim True,
So, how could I remove the “AND” without using [each related]?
Maybe some snippet could help me?
Are you displaying the ID’s or are you using them to be placed into something else. That’s what I was wondering, ie if you’re using the ID’s to be sent into another shortcode, etc.
If the latter, then you probably just want to process the posts with PHP instead.
Thread Starter
alexnn
(@alexnn)
Hello,
I use the ID’s to be sent into another shortcode
That’s what I thought, you’re probably going to have to a PHP output filter to send the value in the field into a PHP function to return the value in the format you’re wanting.
ie, if you pass {@related} to a PHP function, it will pass that as an array, so you could do {@related,join_with_commas} and put the following function in your functions.php (or somewhere in your own plugin, etc.):
function join_with_commas ( $array ) {
return implode( ",",$array );
}
implode will join the values of the array with the character intended. Since the relationship magic tag stores the ID’s of the connected post types, this _should_ work, but you might want to test yourself. I’m not by any means a PHP Developer 😉
Thread Starter
alexnn
(@alexnn)
Hello Jim,
Thank you so much for leading me on the right path.
I twisted and changed this code for about 3 days… and I did it with function with_commas and {@related.ID,with_commas}!
p.s. I’m not a PHP Developer too, I’m just an energy engineer )
Thread Starter
alexnn
(@alexnn)
Hello Jim,
and next, how to get taxonomies (‘category’) term id for {@related} and separate them with commas?
I mean some function , something like this {@related.category.term_id,with_commas}
-
This reply was modified 7 years, 6 months ago by
alexnn.
You should be able to use the same method; if that’s WordPress’s default categories, that would be post_category.term_id.
PS: I’m not a PHP developer either, I just play one on Support 😉
Just realized you’ve resolved your question so marking it resolved.