0

I use this to display all categories:

<?php $args = array(
    'child_of'            => 0,
    'current_category'    => 0,
    'depth'               => 0,
    'echo'                => 1,
    'exclude'             => '',
    'exclude_tree'        => '',
    'feed'                => '',
    'feed_image'          => '',
    'feed_type'           => '',
    'hide_empty'          => 1,
    'hide_title_if_empty' => false,
    'hierarchical'        => true,
    'order'               => 'ASC',
    'orderby'             => 'name',
    'separator'           => ' ',
    'show_count'          => 0,
    'show_option_all'     => '',
    'style'               => 'h3',
    'taxonomy'            => 'category',
    'title_li'            => __( 'Categories' ),
    'use_desc_for_title'  => 1,
); 

var_dump( wp_list_categories($args) );  ?>

But it also gives me back the word "NULL".

enter image description here

How can I remove the "NULL"?

2 Answers 2

0

Function wp_list_categories has an argument echo with you have set to 1 (true). When if it is set to true, instead of returning the value, the function will output the content. Because nothing was returned the var_dump displays null.

Change the echo to false in your arguments array to have the value returned.

1
  • Thank you for your Help! Sadly it wasn't it. NULL disappears, therefor string(244) " appears.
    – gimsech
    Dec 5, 2021 at 19:02
0

I solved it. It seems the NULL came trough the $args.

            <?php wp_list_categories( array(
   'child_of'            => 0,
    'depth'               => 0,
    'echo'                => 1,
    'exclude'             => '',
    'exclude_tree'        => '',
    'feed'                => '',
    'feed_image'          => '',
    'feed_type'           => '',
    'hide_empty'          => 0,
    'hide_title_if_empty' => 1,
    'hierarchical'        => 0,
    'order'               => 'ASC',
    'orderby'             => 'title',
    'separator'           => ' ',
    'show_count'          => 0,
    'show_option_all'     => 'A – Z | ',
    'style'               => 0,
    'taxonomy'            => 'category',
    'use_desc_for_title'  => 1
    ) ); ?>

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.