WordPress.org

Ready to get started?Download WordPress

Forums

cat_is_ancestor_of quit working in custom template (2 posts)

  1. colleengreene
    Member
    Posted 8 months ago #

    Hello,

    I've been using a custom template (via custom functions) for a couple of years that displays certain category names/links in a post if those categories are checked. It suddenly quit working, and I don't know why (I did just upgrade to WP 3.6 last week).

    You can see the custom template here (it's the Hike At A Glance Box at the top).

    In my custom_functions file (the Thesis version of functions.php), I start off my custom template as follows:

    /* ****START HIKE AT A GLANCE BOX BEFORE POST**** */
    function hike_post_details() {
    if (in_category('Hike Reviews')) { ?>

    I use 2 instances of dynamically displayed categories. Everything else in this custom template displays correctly still (all fed via custom fields, with the exception of these 2 items that are fed via categories).

    Best Season uses any season child categories (winter, spring, etc.) of the ancestor "hikes by season" category.

    <?php
                foreach((get_the_category('orderby=ID&order=ASC')) as $childcat) {
                if (cat_is_ancestor_of(529, $childcat)) {
                echo $sep . '<a href="'.get_category_link($childcat->cat_ID).'">';
              echo $childcat->cat_name;
                echo '</a>';
                               $sep = ' ';
            }
            }
            ?>

    And Difficulty uses any difficult child categories (easy, moderate, etc.) of the ancestor "hikes by difficulty" category.

    <?php
                foreach((get_the_category('orderby=ID&order=ASC')) as $childcat) {
                if (cat_is_ancestor_of(114, $childcat)) {
                echo $sep . '<a href="'.get_category_link($childcat->cat_ID).'">';
              echo $childcat->cat_name;
                echo '</a>';
                               $sep = ' ';
            }
            }
            ?>

    Despite having all of the necessary parent/child categories selected, these fields now appear blank on every single one of my posts.

    Like I said, this has worked great for a couple of years, but suddenly quit working. The only change I have made in the last couple of weeks (when they last displayed fine) is upgrading to the most recent version of WordPress.

    Any help is appreciated. Thank you!

  2. colleengreene
    Member
    Posted 8 months ago #

    I used some alternative code to fix both of the above issues, but I'd like to not mark this thread Closed in case someone can explain to me why my original code suddenly quit working after 2 years.

    thank you.

Reply

You must log in to post.

About this Topic