funkhaus / fuxt-backend

A theme that turns WordPress into a true Headless CMS. Optimized for the fuxt frontend boilerplate and fuxt-api plugin.
GNU General Public License v3.0
101 stars 19 forks source link

Enable ACF custom taxonimes and post types made in the UI to show in GraphQL #67

Closed drewbaker closed 9 months ago

drewbaker commented 1 year ago

Currently the ACF plugin allows you to create a custom taxonimes and post types through the UI.

But it doesn't yet allow you to enable those in WP-GQL. I know it's planned to allow this, but in the meantime I'd like to auto enable all the ones that are made by ACF that also have show in rest API enabled (see screenshot).

For example, here is the code that allows you to set a pre-made taxonomy to show in GQL:

add_filter( 'register_taxonomy_args', function( $args, $taxonomy ) {

  if ( 'doc_tag' === $taxonomy ) {
    $args['show_in_graphql'] = true;
    $args['graphql_single_name'] = 'documentTag';
    $args['graphql_plural_name'] = 'documentTags';
  }

  return $args;

}, 10, 2 );

So it would just be a matter of making that work for custom post types too, and to do some test for show_in_rest to be true also.

Screenshot 2023-10-03 at 6 09 10 PM