Support

Account

Forum Replies Created

  • Looking at the documentation again for acf_register_block_type(), there is an option for post_type restriction:

    'post_types' => array('post', 'page'),

    This seems to take care of the category issue, too. If the category is empty, it will not show.

    Potentially solved?

  • An update on this if people would like to try to do the same thing. I do have a working function to get this done, it’s a bit hacky, but it’s working. It’s in a somewhat controlled environment, so this works for what we need.

    What’s being done is I’m taking the saved ACF block “JSON” from the wp_post table and spitting it out. Upon doing that, I’m doing a find/replace of all the extra characters that aren’t necessarily JSON friendly to make it JSON friendly. Once that’s complete, I’m using json_decode() to turn it into an editable format and update the fields that need updating. To save it, I use json_encode() to turn it back into JSON. Once again, while it may be unnecessary, I use json_decode($var, true) to turn it into a PHP array so I can add back the elements that are required with ACF.(<!– wp:acf/… and so fourth). Then I can save the post back to the database and successfully update my field(s) from the front end.

    Hopefully this helps anyone looking to do the same, or similar thing. If you’d like me to post my code, let me know…there is probably a better way of doing this.

  • @kyfr4n, yea same for me…about merging the categories. I have several different custom post types that I want to have different categories display for each. But when I separate them out using conditionals, only one will show where the other won’t register (in this case, the first conditional won’t register), even though the conditional statement is working. Since only one is registering, the custom blocks using the acf_register_block_type() that are tied to the non-working category aren’t registered which leaves me with the error I stated in my previous post. If I put all the block categories together as one, like you said, it’ll work.

    Seems we’re having a similar issue. It worked great for me until the official 5.8.0 update. I was using 5.8.0 RC1, prior. Hopefully this will be addressed if more folks have the same issue.

  • I’m having issues as well with multiple block categories and registering blocks to those categories. Whereas selecting multiple areas (CPT’s in this case), only one category is displaying at a time. And only one grouping of blocks will show (whichever is written first). The other I’m getting the Your site doesn't include support for 'acf/... block error. Not sure what the issue is there…

    At any rate, with your situation, you may want to attempt to merge the $categories and $welcoop_blocks arrays. Perhaps something like this may work for you:

    function ff_block_category( $categories, $post ) {
    
    	if ( $post->post_type == 'page' ) { 
    
    		$welcoop_blocks = array_merge(
    			$categories,
    			array(
    				array(
    					'slug' => 'headers',
    					'title' => __( 'WELCOOP Headers', 'mlp-admin' ),
    				)
    			)
    		);
    
    	} else {
    
    		return $categories;
    
    	}
    
    	return $welcoop_blocks;
    }
    add_filter( 'block_categories', 'ff_block_category', 10, 2);

    Hopefully that helps.

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