• Resolved chris2604slvstr

    (@chris2604slvstr)


    Hi support !

    I am using your plugin to create a post type “Events”. I set many categories for an event. I would like to know how to get the default category I set for this post.

    I am using a different category for this event than the default website category.

    I tried to get the info thanks to the get_terms() function, but it’s just returning me all the categories I set for the event.It is not giving me any info about which one is the default category that I set before to publish the event.

    Any suggestion ?

    Thanks in advance !

    Chris

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Are you referring to the default category that you set in the options panel? Which is “uncategorized” by default with a new install? If yes, then get_option('default_category'); will get you that much.

    If you’re talking about something like “Primary Category” that Yoast makes use of then you may need a touch of custom code like what’s found at https://stackoverflow.com/a/38800804 to fetch regularly.

    Otherwise, I’m not familiar with any other “default category” setups that you may be using, so I can’t provide any best ways to retrieve. Willing to hear what you have and offer potential suggestions once I know how the detail is stored.

    Thread Starter chris2604slvstr

    (@chris2604slvstr)

    Thank for your answer.

    I created a custom post type : “Events”. I also created a custom taxonomy : “Categories”, for this custom post type. Well, I can set many “Categories” for a post created from the custom post (Events) : For example, for an new event, I can set “Party”, “Pool”, “Free” as “Categories”.

    Then, I can define the main “Categories” for the new post. I can set that the main “Categories” is “Pool”.

    Finally, My question is, how may I get the title, or the ID of this “Categories” set as default “Catégories” ?

    Is it more clear ?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I definitely understand the concept and idea. It’s the “how is a specific category marked as primary” part that isn’t clear yet and still.

    For example, is the UI to set the primary category looking like something in the first image at https://www.tannerrecord.com/how-to-get-yoasts-primary-category/ ? with a link to the right say “Make primary” ? If exactly that, then the Yoast SEO link there or the StackOverflow link from my previous reply will be your best bet.

    Otherwise, I’d need to know how primary choice is being stored, what exactly is stored, and details like that, in order to provide any guidance.

    Thread Starter chris2604slvstr

    (@chris2604slvstr)

    Hello !
    That’s exactly what I needed. Thanks for your answer ! I close the ticket.
    Chris

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Get the default category set for a post using custom post type’ is closed to new replies.