• Resolved jasonsweb

    (@jasonsweb)


    Hi!

    For my custom theme I’m trying to populate a dropdown menu in my meta box with my custom taxonomies.

    I’m using this code to get the custom taxonomies:

    $types = get_terms('portfolio-category');
    $types_array[0] = 'Select all';

    if ($types) {
    foreach($types as $type) {
    $types_array[$type->term_id] = $type->name;
    }
    }

    But then I’m getting this error in my WP-admin:
    Trying to get property of non-object

    Really, I don’t have any idea what I’m doing wrong??

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What if you try

    if ($types) {
     foreach($types as $type) {
      if ( $type ) {
       $types_array[$type->term_id] = $type->name;
      }
     }
    }

    Thread Starter jasonsweb

    (@jasonsweb)

    Thanks for your reply.
    Unfortunately the same error…

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I’ve just edited my code, can you try again please?

    Thread Starter jasonsweb

    (@jasonsweb)

    Still not working unfortunately. Getting the same error. ??

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    If you have PHP 4/5, try this

    if ($types) {
     foreach($types as $type) {
      if ( is_object( $type ) ) {
       $types_array[$type->term_id] = $type->name;
      }
     }
    }

    Thread Starter jasonsweb

    (@jasonsweb)

    The error disappeared, but the dropdown list is empty.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Taxonomy Dropdown’ is closed to new replies.