Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a taxonomy called mailers

And I am adding new terms to this taxonomy on a monthly basis.

For example these are my 4 recent terms (slugs) I have added...

'august-2012-newsletter'
'july-2012-newsletter'
'june-2012-newsletter'
'may-2012-newsletter'


Is there anyway way to get the latest added term and added it to my $mailer variable?

Instead of having manually type the latest term in every month?


$mailer = 'august-2012-newsletter';

$articles = new WP_Query(array(

    'mailers'       => $mailer, 
    'order'         => 'ASC',
    'orderby'       => 'meta_value',
    'meta_key'      => 'mailer_order',
    'post_type'     => 'post'

));


Thank you so much for any ideas :-)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The latest term means it'll have the highest term_ID right, So we're sorting terms in DESC order and getting first array element of the result in $latest_mailer variable.

Here's code to do that, not tested but if didn't worked - you can modify get_terms() function to return term with higest id.

$mailer = get_terms('mailers','orderby=id&order=DESC&number=1');
$latest_mailer = $mailer[0]->slug;
share|improve this answer
    
This worked perfect - thank you Amit –  Joshc Aug 9 '12 at 13:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.