Support » Plugin: Advanced Custom Fields: Extended » Custom Post Types not registering taxonomies?

  • Resolved n_feragnoli

    (@n_feragnoli)


    Hello, thank you for your work, this is a great plugin.
    I am having trouble with assigning taxonomies to Custom Post Types.
    The Custom Post Type I created (in the admin UI) has the default ‘category’ taxonomy enabled yet a WP_Query returns post objects without any taxonomy terms.
    Am I missing something..?

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • laymonk

    (@laymonk)

    I don’t think enabling taxonomy support will automatically pull in taxonomy terms in queries. You will need to link in the taxonomy via a field in metabox / field group associated with the post-type.

    ie, you will have to create a field of type ‘taxonomy’ in a field group associated with the post-type. In that field, you tell it which taxonomy to use … and that’s the real link. Enabling a taxonomy on it’s own is just like a capability definition.

    I hope I have read your problem right … also, I am certainly far from an expert on the subject 🙂

    Thread Starter n_feragnoli

    (@n_feragnoli)

    hi, thanks for the answer.
    yes, I think you understood correctly. That is, however, somewhat confusing because creating custom post types in ACF Extended does indeed give the option to specify what taxonomies the type supports and, consequently, the ‘categories’ metabox appears in the ‘new post’ page for the custom post.

    all the same, adding a field group for the custom post seems not to pull any custom field in WP_query either..?

    laymonk

    (@laymonk)

    The concept of support is only a backend presentation thing, in the sense that those taxonomies show up in backend entry forms for the custom post type … but there is no real linkage as such.

    To create a link, you don’t just need a field group … you need to define a field of type ‘taxonomy’ within that field group, and in that field’s definition you choose the taxonomy you want it to link to.

    See acf docs on taxonomy field type: https://www.advancedcustomfields.com/resources/taxonomy/

    Plugin Author hwk-fr

    (@hwk-fr)

    Hello,

    Thanks for the feedback! As @laymonk pointed out, Post Types / Taxonomies registration are declarative, what makes the actual link between them is to have a term set on a post.

    Once the link is created, in your WP_Query you’ll have to use the tax_query parameter in order to retrieve specific posts from specific terms. See WP_Query documentation: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

    I would recommend to also take a look at the native register_post_type() and register_taxonomy() functions (which are used behind the scene by ACF Extended) to fully understand Post Types & Taxonomies relations.

    Hope it helps!

    Regards.

    Thread Starter n_feragnoli

    (@n_feragnoli)

    ok, thanks for your help

    Plugin Author hwk-fr

    (@hwk-fr)

    You’re welcome!

    Have a nice day.

    Regards.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Post Types not registering taxonomies?’ is closed to new replies.