Archived topic
Post meta placeholder?
3 replies · Started by David on June 28, 2022
Hello
I've set up a query loop for a custom post type of teams on this page...
https://www.octagongroup.co.uk/meet-the-team/
The text fields under the specialisms and fun fact are bought in using dynamic data on a heading block using Post meta from an ACF field. Problem is if they don't fill anything in the field, it's going to mess up the layout - can I add placeholder text for empty ACF fields?
Also, how can I get the query loop to list in alphabetical order taken from the title (name)?
Thanks
Dave
Hi there,
i am not 100% on this but you could try the following snippet:
function db_placeholder_meta( $block_content, $block ) {
$subtitle = (float)get_post_meta( get_the_ID(), 'taq_review_score', true );
if ( ! empty( $block['attrs']['className'] ) && 'custom-meta' === $block['attrs']['className'] && empty($block_content) ) {
$block_content = '<p>Your placeholder HMTL</p>';
}
return $block_content;
}
add_filter( 'render_block', 'db_placeholder_meta', 10, 2 );
If you give the Block a class of: custom-meta then that filter will look for that element, and if the $block_content is empty then it should return the placeholder.
Thanks David, I'll give that a go.
Let us know how you get on!