Taxonomy Advanced: Set starting node of categories with query_args

Support General Taxonomy Advanced: Set starting node of categories with query_argsResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #29101
    JugiburJugibur
    Participant

    Hi,

    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!

    Juergen

    #29105
    JugiburJugibur
    Participant

    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!

    #29106
    JugiburJugibur
    Participant

    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.

    #29116
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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 https://docs.metabox.io/custom-field-type/
    and refer to this topic https://support.metabox.io/topic/select-a-gravity-form-to-assign-to-a-cpt/

    #29120
    JugiburJugibur
    Participant

    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 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.