> If you create an ACF block and assign the field group to the block, you will at least be able to fill out the fields within the block. If the fields are for a CPT, you can add that block to a block template for the CPT, so that it’s there automatically when you create a new CPT post.
The fields created by ACF blocks are not saved as custom fields, so they’re not post meta. Therefore, this is not necessarily a solution.
A possible solution:
I found changing the position to “High (after title)” ('position' => 'acf_after_title'
) put the fields back in the main area, below the block editor.
@pooya is correct, field['_name']
works for checklists (not select or multiselect) taxonomy fields.
function taxonomy_depth( $args, $field ) {
if( 'TAXONOMY_NAME' === $field['_name'] ) {
$args['depth'] = 1;
}
return $args;
}
I’m also interested to know how this might be done. Same goes for the new block variations, which is really cool.
ref: https://make.wordpress.org/core/2020/02/27/introduce-block-variations-api/
In case anyone else is looking for an answer, I found a solution…
Use block filters.
The blocks.registerBlockType
filter lets you modify block settings. So, I just added a parent setting with the block I wanted as a parent. Since the parent prop takes an array of blocks, more than one parent can be named.
/**
* Set ACF block parent
* @param {obj} settings
* @param {string} name
*/
function setBlockParent( settings, name ) {
if ( name !== 'acf/post-content' ) {
return settings;
}
return lodash.assign({}, settings, {
parent: [
'namespace/featured-content',
]
} );
}
addFilter(
'blocks.registerBlockType',
'namespace/set-post-content-parent',
setBlockParent
);
Hope it helps anyone else.
ref: https://developer.wordpress.org/block-editor/developers/filters/block-filters/#filters
Following up on this… Still looking to see if there is a way to set a parent for blocks registered with ACF?
The load value filter documentation is here:
https://www.advancedcustomfields.com/resources/acf_load_value/
@lucidlips I might be confused, but I think this question is about filtering the ACF relationship field UI to exclude draft posts (admin), not how to not show draft posts on the front-end.
Your solution it explains how to exclude posts of a certain status from a loop, which I’m sure is helpful to many. But, it hasn’t nothing to do with ACF, but rather post loops.
BTW. post_status
is a column in the wp_posts
table and is returned with the WP_Post
object, so you could also use this condition:
<?php
if ( 'publish' === $post->post_status ){
// loop code
}
?>
ref: https://codex.wordpress.org/The_Loop
ref: https://codex.wordpress.org/Class_Reference/WP_Post
@hube2 Thanks. This is something I know how to create manually, but I want to keep the UI (ACF) consistent, so didn’t want to go that route.
Ultimately, I think I’m going to try to come up with a different solution.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.