Why the value of the selector doesnt remain visible in the custom field after I edit the post?

There’s nothing in your code that would allow this to happen. In your HTML you need to add a selected attribute to the <option> element representing the current value. WordPress includes a helper function, selected() which can help with this: function camere_meta_box_render( $post ){ $number = get_post_meta( $post->ID, “function_camere”, true ); echo ‘<div><select name=”function_camere”>’; for( … Read more

Can I count every article following extracted meta value?

Use array_count_values() (untested): <?php $posts = get_posts( array( ‘numberposts’ => -1, ‘category_name’ => ‘bird’, ‘order’ => ‘ASC’, ) ); if ( $posts ) { foreach( $posts as $post ) { $species[] = get_post_meta( $post->ID, ‘species1’, true ); $species[] = get_post_meta( $post->ID, ‘species2’, true ); } } $species = array_filter( $species ); $counts = array_count_values( $species … Read more

How to conditionally display an ACF custom textarea contents only to those users chosen from an ACF User field

I’m quite new to this so I might be the wrong person to answer your question but: get_field(‘allowed_users’) Returns an array of user IDs so you can’t directly use in_array() So if you change the if statement to: if (is_array($allowed_users) && in_array($current_user_id, $allowed_users)) Hopefully it will work.

How to display WordPress Twenty Twenty-Four’s built-in custom field in a post (or page)?

WordPress’s Twenty Twenty-Four theme makes it possible to add custom fields directly in the editor This UI is not coming from TwentyTwentyFour, and was added to WP decades ago: https://wordpress.org/documentation/article/assign-custom-fields/ It predates 2024/2023 and was even present when the original Kubrick theme was the default theme, this is because it’s a part of WordPress itself. … Read more

get_the_ID() retrieves same ID on Gutenberg’s Query Loop

No, you did nothing wrong. It’s a known issue and in WordPress v6.1.3 and up to the current stable release as of writing (v6.2.2), it’s happening because of the following lines in get_the_block_template_html() which returns the markup for the current (block-based) template: $content = do_shortcode( $content ); $content = do_blocks( $content ); So as you … Read more

Automatically changing a posts status to draft based on magic fields [closed]

For cron jobs, take a look at the Transients API. The rest could maybe be acchieved with something like the following. I have never ever used the transient API before and code’s not tested. function set_post_to_draft() { global $post; if ( get_post_meta( $post->ID, ‘set_to_draft_key’ ) == true ); return $post->post_status == ‘draft’; } set_transient( ‘post_to_draft_transient’, … Read more