WordPress.org

Ready to get started?Download WordPress

Forums

Using get_terms to show top-level only, if children have posts (2 posts)

  1. SpankMarvin
    Member
    Posted 2 years ago #

    Hi there

    I'm trying to do something that seems pretty simple, but I'm running into issues. Basically I have a structure like the following:

    - Art
    -- Abstract
    -- Landscape

    - Textures
    -- Texture 1
    -- Texture 2

    These are item categories in a custom post type. So, on my home page, I'm trying to list all the TOP LEVEL terms in the taxonomy (Art and Textures) but ONLY show them if one or more of the child terms has a post assigned. No issues, there, except that the top-level term does not appear if it is not explicitly assigned to a post too. I want the user to be able to omit assigning ART to an ABSTRACT post (i.e. they should be able to assign ABSTRACT only) and for that to trigger showing ART on the home page.

    Currently I get all or nothing. Specifying parent => 0 returns top-level, but only if that top level category has a post explicitly tied to it. Not defining parent => 0 gives me all the terms, which I don't want.

    Any advice would be greatly appreciated!

    Thanks

    John

  2. SpankMarvin
    Member
    Posted 2 years ago #

    As a digest to the above, I could just summarize by saying:

    I need to use get_terms to show top-level only, if children have posts but not necessarily if the top-level parent explicitly has posts.

    Ahem.

Topic Closed

This topic has been closed to new replies.

About this Topic