Support

Account

Forum Replies Created

  • Okay, I came up with my own solution here. It’s very similar to the PHP export solution but just uses the same function in ACF that the JSON import uses. The code for the most part is just copied from the JSON import tool. In order to call this, I just created a special page that executes the code as long as the user is an admin.

    class AcfInit
    {
      public static function install()
      {
        $json = self::jsonExport();
    
        $json = json_decode($json, true);
    
        // Check if empty.
        if( !$json || !is_array($json) ) {
          echo "Invalid data";
          return;
        }
    
        // Ensure $json is an array of groups.
        if( isset($json['key']) ) {
          $json = array( $json );
        }
    
        // Loop over json
        foreach( $json as $field_group ) {
          // Search database for existing field group.
          $post = acf_get_field_group_post( $field_group['key'] );
          if( $post ) {
            $field_group['ID'] = $post->ID;
          }
    
          // Import field group.
          acf_import_field_group( $field_group );
        }
    
        echo "done!";
      }
    
      public static function jsonExport()
      {
        return 'JSON EXPORT CONTENTS GO HERE';
      }
    }
  • Is there a command line version of the tool to import the data?

  • isset($query->query["category_name"]) is false for the ACF queries. I just var dumped the $query for everything that matched is_category() and was able to isolate the two.

  • John,

    You are a life saver… I’ve identified it down to my custom theme where I have a pre_get_posts filter. My filter was in place so that I could display custom post types on a category page.

    Strange behavior though… When ACF is retrieving the field meta data it is being identified as a category is_category() == true. What I noticed is that the meta query doesn’t have a category name so I just added a check for that and everything is happy now.

    Any idea why the custom field query is being identified as a category?

    My original filter ($this->customPostTypes has my custom post type names):

    
    if (is_category()) {
          $postType = get_query_var("post_type");
    
          if (!$postType) {
            $postType = [
              "nav_menu_item",
              "post",
            ];
    
            foreach ($this->customPostTypes as $customPostTypes) {
              $postType[] = $customPostTypes["type"];
            }
          }
    
          $query->set("post_type", $postType);
        }
    
        return $query;
    

    Updated filter:

    
    if (is_category() && isset($query->query["category_name"])) {
          $postType = get_query_var("post_type");
    
          if (!$postType) {
            $postType = [
              "nav_menu_item",
              "post",
            ];
    
            foreach ($this->customPostTypes as $customPostTypes) {
              $postType[] = $customPostTypes["type"];
            }
          }
    
          $query->set("post_type", $postType);
        }
    
        return $query;
    
Viewing 4 posts - 1 through 4 (of 4 total)