Custom Fields
Support General Taxonomy Advanced: Set starting node of categories with query_args

  • Creator
  • #29101
    Resolved Jugibur


    I want allow only select child nodes from a special hierarchical category (or the main category itself).
    If have tested this base code and it works outside of the Meta Box configuration:

    $terms_list = get_terms(array('taxonomy' => 'happyfiles_category', 'hide_empty' => false, 'parent' => 5));
    print '<pre>' . print_r($terms_list, true) . '</pre>';

    So I tried it with the 'query_args' key in this matter:

    'query_args' => array(
      //'taxonomy' => 'happyfiles_category', 
      'hide_empty' => false,
      'posts_per_page' => - 1,
      'parent' => 5

    But unfortunately I get following messages in backend:

    Notice: Undefined offset: 0 in /Users/hoefs/Essentiell/Websites/htdocs/dab-wp-base/wordpress/wp-content/plugins/meta-box/inc/walkers/select-tree.php on line 52
    Notice: Trying to get property 'parent' of non-object in /Users/hoefs/Essentiell/Websites/htdocs/dab-wp-base/wordpress/wp-content/plugins/meta-box/inc/walkers/select-tree.php on line 52
    Notice: Undefined index: in /Users/hoefs/Essentiell/Websites/htdocs/dab-wp-base/wordpress/wp-content/plugins/meta-box/inc/walkers/select-tree.php on line 70
    Warning: Invalid argument supplied for foreach() in /Users/hoefs/Essentiell/Websites/htdocs/dab-wp-base/wordpress/wp-content/plugins/meta-box/inc/walkers/select-tree.php on line 81

    Does someone have a clue how to fix this? Thanks in advance!


Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #29105

    After changing the field_type to 'select' (and not 'select_advanced') it now works! No warning messages any more. But perhaps you could solve this problem for 'select_advanced'. Thanks!


    I am attaching the following question to this thread as it relates to solving the problem...

    Unfortunately the option "parent" in the query_args() limits the hierarchy to the immediately following child-nodes.
    My idea is to use a hook to be able to return all following child-nodes with my own function result. Is there a way to do this with the select field type? In the docs of this field I can't find an answer to this problem.

    Long Nguyen


    The message shows the error with the field select_tree, not select_advanced

    Notice: Undefined offset: 0 in /Users/hoefs/Essentiell/Websites/htdocs/dab-wp-base/wordpress/wp-content/plugins/meta-box/inc/walkers/select-tree.php on line 52

    the query args setting parent does not work with the select_tree field but works well with the select_advanced field. Can you please re-check it?

    If you want to show all child terms on select, you can create your own custom field type. Follow this documentation to get more details
    and refer to this topic


    Hi Long,

    thanks for your reply! Yes, select_advanced works without errors but missing the hierarchy selection.

    I'm using now the 'checkbox_tree' (without 'parent' query_args) and hiding the unwanted items (siblings) with CSS.
    It's still not optimal , especially for a lot of items, because it takes up a lot of space, but it's good enough for now.

    But if I have more time I will take a lock at the docs for a customt type and give it a try.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.