Auto delete post if certain custom field data is empty

kses_remove_filters(); $new_id = wp_insert_post($post_arr, true); kses_init_filters(); if (is_wp_error($new_id)) { $this->write_log(“error occurred in wordpress post entry: ” . $new_id->get_error_message() . ” ” . $new_id->get_error_code(), true); return; } if($url) update_post_meta($new_id, ‘source_link’, $url); else { // wp_delete_post($new_id); // Move post to trash $deleted = wp_delete_post($new_id, true); // Permanently delete post if(! $deleted ){ $this->write_log(“error deleting post entry.”, true); … Read more

Adding dropdown select meta box to custom post type – seems restAPI is interfering

But I don’t understand: why does the mere act of checking off that a post type is visible to restAPI cause wordpress’s backend editor to go into a completely different mode of operation? WordPress 5.0 introduced the Block Editor. This is an entirely new post editing screen and method of editing posts. It works by … Read more

Publish an XML feed from a CPT with ACF fields?

Here’s a fairly complete example of one way to do this. Let’s register a Job post type that will be used with our feed. /** * Register Job post type * https://developer.wordpress.org/reference/functions/register_post_type/ */ function wpse_register_job_post() { $book_args = [ ‘label’ => __( ‘Jobs’, ‘textdomain’ ), ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘show_in_menu’ … Read more

Importing hard coded custom field into acf field

First off, you should know that get_post_meta() doesn’t create any custom fields (or metadata), it only retrieves the custom field’s value. But the WordPress functions that do create custom fields (for posts) are add_post_meta() and update_post_meta(). So that get_post_meta($post->ID, “mt_post_subtitle”, true) simply retrieves the value of the meta/field named mt_post_subtitle for the post (referenced by … Read more

How do I create a column in Users list and display user data from custom registration field

Use the following code to add new column and show data properly. function add_user_columns_hospital( $column ) { $column[‘hospital’] = ‘Hospital’; return $column; } add_filter( ‘manage_users_columns’, ‘add_user_columns_hospital’ ); function modify_user_table_row_hospital( $val, $column_name, $user_id ) { switch ($column_name) { case ‘hospital’ : return get_the_author_meta( ‘user_registration_hospital’, $user_id ); default: } return $val; } add_filter( ‘manage_users_custom_column’, ‘new_modify_user_table_row’, 10, 3 … Read more

How to change post featured image using a custom field of category?

You could filter the the_post_thumbnail() function, which will dynamically show the assigned category image across all your custom post type, rather than using acf_save_post to save the category image in the post featured image meta field. By filtering the the_post_thumbnail() for your specific post type, this means if you change the image on category in … Read more