WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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

Your Answer


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.