Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Filtering Category Lists

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28973
    sBowers
    Participant

    (Not sure if this questions belongs in wordpress or php)

    I am filtering wordpress posts on a template using:

    Code:
    $cat,
    ‘showposts’ => $showposts,
    ‘caller_get_posts’ => $do_not_show_stickies
    );
    $my_query = new WP_Query($args);
    ?>

    I need to filter

    Code:
    wp_list_categories()

    list based on the page or category. ie On page "36" the list should only display categories "3" and the sub-categories under "3".

    I think I am close. I used the same if statement in the sidebar file to set a variable $cat

    Code:
    $cat,
    ‘title_li’ =>”
    );
    ?>

    and then I call

    Code:

    But I am getting the following error:

    Quote:
    Warning: preg_split() expects parameter 2 to be string, array given in (path to) wp-includes/taxonomy.php on line 696

    I can hard code the "include" into the

    Code:

    and it works fine.

    Can you not pass a variable into this statement?

    Any assistance is appreciated.

    Seth

    #75325
    Chris Coyier
    Keymaster

    The "include" parameter wants a string, not an array. Just give it "3" instead of array(3). If you need multiple, just comma separate, like "3,4,5"

    #75327
    sBowers
    Participant

    So I was making it too complicated.

    You have to call the hook during the if statement. ie

    Code:
    if (is_page(’36’) ) {
    wp_list_categories(‘child_of=3&title_li=’);
    } elseif ( is_page(’42’) ) {
    wp_list_categories(‘child_of=4&title_li=’);
    } elseif ( is_page(’44’) ) {
    wp_list_categories(‘child_of=5&title_li=’);
    } else {
    wp_list_categories();
    }

    It will still need to be hard coded if the site changes but at least it works for now.

    #75328
    sBowers
    Participant
    "chriscoyier" wrote:
    The "include" parameter wants a string, not an array. Just give it "3" instead of array(3). If you need multiple, just comma separate, like "3,4,5"

    Thanks Chris. Love the screancasts. You have saved my bacon more then once.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.