I am trying to get the slug of a custom taxonomy for the current post that this shortcode is embedded in if the user doesn't define the slug he wants explicitly in the shortcode.

function get_date_posts($params, $content){
        $default_params = array(
            'post_type'     => 'post',
            'order'         => 'asc',
            'orderby'       => 'meta_value',
            'posts_per_page'=> 5,
            'meta_key'      => 'fl_date_picker'

        $terms = get_the_terms( $post->ID, 'calendar_event_type' );
        if ( !empty( $terms ) ){
        $params['slug'] = array_shift( $terms );


This line is causing the error: $params['slug'] = array_shift( $terms );

Catchable fatal error: Object of class stdClass could not be converted to string

How can I get around this? Tried everything to convert this to a string..

1 Answer 1


You don't specify where exactly the error comes from but I assume your problem is that you assign an object to the slug instead of a string. your code should look like

$t = array_shift( $terms );
$params['slug'] = $t->slug;
  • 1
    Apart from that, $post is also an undefined variable in context, failing $terms. :-) Commented Feb 24, 2015 at 5:44
  • $post seems to work
    – JoaMika
    Commented Feb 24, 2015 at 11:32
  • @JoannaMikalai, you should still add it as a global or as a parameter to the function. It is possible that it works just because some default handling of error condition gives you the correct result Commented Feb 24, 2015 at 12:04
  • ok how can i make it to tie to the argument ''post_type' => 'post'' ?
    – JoaMika
    Commented Feb 24, 2015 at 12:27
  • should I just change this to 'post_type' => $post, ?
    – JoaMika
    Commented Feb 24, 2015 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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