Support

Account

Home Forums ACF PRO Relationship field displaying posts & categories

Solving

Relationship field displaying posts & categories

  • Hi awesome guys at ACF. Your plugin is amazing and has saved me 100s of hours of work.

    I am looking to use the relationship field to display posts as well as categories in the list. Meaning the user can select Posts AND/OR categories. The idea is that there will be a page with posts and categories all on the same page in a certain order.

    I know you can override the WP_Query in acf/fields/relationship/query, but it will still only return posts as far as I know. How can I get the categories of posts separately and add it to the list?

    Many thanks

  • Hi @jasonkapadia

    Could you please tell me where do you want to do it? The backend or front end?

    I’m afraid WordPress doesn’t allow you to mix the query between posts and taxonomies. This page should give you more idea about it: https://codex.wordpress.org/Class_Reference/WP_Query. As a workaround, maybe you can get the posts and taxonomies in variables and order them manually by using PHP code.

    I hope this makes sense ๐Ÿ™‚

  • Hi James

    I want to do it on the backend only, using the great UI you guys have for the relationship field type.

    In this work around you speak of, would I theoretically be able to include both posts and categories in the single relationship field UI?

  • Hi @jasonkapadia

    I’m sorry I forgot to tell you that the workaround will only work if you want it on the front end.

    ACF saves relationship data as the posts or terms ID in the database. If you put them in the same entry, ACF will be confused when it tries to show the data. Please use the taxonomy field type for the taxonomies instead.

    Hope this makes sense ๐Ÿ™‚

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

You must be logged in to reply to this topic.