• wp_set_post_categories( 123, array(1,2)

    Seems to set the two categories on post 123 – but does NOT set one as a primary category.

    My Google-foo is failing as I can seem to find no way to set the primary category on a post.

    Thee must be a method.

    TIA

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Hi Alan,
    AFAIK there is no primary category. Top level hierarchy, yes. Not primary per post. At least not in core WP. Of course one will appear first before the others, but it’s a matter of what the query found first, it’s not a user designation.

    Of course themes or plugins could implement some sort of primary scheme. Perhaps manage which term through post meta?

    Thread Starter Alan Fuller

    (@alanfuller)

    I was unaware of such a concept.

    But if you do the above call and then go to a post – both categories in the post editor have ‘set to primary’ next to them and if you click one it disappears.

    2023-01-16-20-34

    Thread Starter Alan Fuller

    (@alanfuller)

    I guess i’m going to have to look at the WP code that handles that

    Thread Starter Alan Fuller

    (@alanfuller)

    You are right – it is an SEO plugin that is doing it.

    Another rabbit hole navigated!

    • This reply was modified 1 year, 10 months ago by Alan Fuller.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Set post primary category’ is closed to new replies.