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...


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 :-)


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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