WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Taxonomy Dropdown (7 posts)

  1. jasonsweb
    Member
    Posted 1 year ago #

    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!

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    What if you try

    if ($types) {
     foreach($types as $type) {
      if ( $type ) {
       $types_array[$type->term_id] = $type->name;
      }
     }
    }
  3. jasonsweb
    Member
    Posted 1 year ago #

    Thanks for your reply.
    Unfortunately the same error...

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

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

  5. jasonsweb
    Member
    Posted 1 year ago #

    Still not working unfortunately. Getting the same error. :(

  6. Andrew
    Forum Moderator
    Posted 1 year ago #

    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;
      }
     }
    }
  7. jasonsweb
    Member
    Posted 1 year ago #

    The error disappeared, but the dropdown list is empty.

Topic Closed

This topic has been closed to new replies.

About this Topic