• Resolved lexiriam

    (@lexiriam)


    I’ve created seven categories in the Portfolio section. I’m unable to pull categories with PHP:

    <div class=”controls”>
    <!– Get a list of all categories in the database, excluding those not assigned to posts –>

    <?php
    $all_categories = get_categories(array(
    ‘hide_empty’ => true
    ));
    ?>

    <!– Iterate through each category –>
    <?php foreach($all_categories as $category): ?>
    <!– Output control button markup, setting the data-filter attribute as the category “slug” –>

    <button type=”button” data-filter=”.<?php echo $category->slug; ?>”><?php echo $category->name; ?></button>
    <?php endforeach; ?>
    </div>

    The only thing that is pulled is “Uncategorized” for the button.

    • This topic was modified 7 years, 4 months ago by lexiriam.
    • This topic was modified 7 years, 4 months ago by lexiriam. Reason: updated issue
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lexiriam

    (@lexiriam)

    better fix was adding the ‘phort_category’ category in the category array of the get_category() function found in the wp-includes/category.php file.

    Plugin Author justnorris

    (@justnorris)

    get_categories() function is only meant to be used for WordPress Post Categories.

    “Categories” are a “post taxonomy”, – just like “Portfolio Categories” are “portfolio taxonomy”, so instead of using get_categories() I recommend that you use get_terms(), something like this:

    
    get_terms('phort_category', array( 'hide_empty' => true ) );
    

    Here’s a link to the documentation: http://developer.ww.wp.xz.cn/reference/classes/wp_term_query/get_terms/

    • This reply was modified 7 years, 4 months ago by justnorris.
    • This reply was modified 7 years, 4 months ago by justnorris.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Categories not being pulled’ is closed to new replies.