How to retrieve custom field types for all posts in WordPress/PHP?

Custom fields are saved as “post meta” which is stored in wp_postmeta. To retrieve them, you use the get_post_meta() function as follows: $value = get_post_meta( $post_id, $meta_key, $single ); $single will almost always be set to true if you’re working string data. Unfortunately, it defaults as false, so if you’re retrieving the data as a … Read more

Change message given when deleting post from custom post type

There’s no hook named post_trashed_messages, but there is the bulk_post_updated_messages hook which you can use to change the bulk action updated messages: add_filter( ‘bulk_post_updated_messages’, function ( $bulk_messages, $bulk_counts ) { $bulk_messages[‘post’][‘trashed’] = _n( ‘%s post successfully deleted.’, ‘%s posts successfully deleted.’, $bulk_counts[‘trashed’] ); return $bulk_messages; }, 10, 2 ); Or to target a specific post … Read more

How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?

The problem is that when the special subscriber tries to Add New a sub-cpt post, it is denied permission. However, when the CPT menu is a top-admin-menu, then everything works out fine. The issue is related to the placement of the CPT’s UI menu in the back-end: if it’s top-level (show_in_menu=TRUE), all is well; if … Read more

Show ACF field from custom taxonomy and display on the single template

I would try something like this… // Assume there is only one category. $product_category = get_the_terms($post, ‘product-category’)[0]; $cat_fields = get_fields(“term_$product_category”); $color = $cat_fields[‘category_colour_primary’]; You could also do this… // Assume there is only one category. $product_category = get_the_terms($post, ‘product-category’)[0]; $color = get_field(‘category_colour_primary’, “term_$product_category”);

Add text to post list/edit screens?

If you are OK with using javascript, you can try the following in your functions.php file: add_action(‘admin_footer’, ‘my_admin_footer’); function my_admin_footer() { $uri = isset($_SERVER[‘REQUEST_URI’]) ? $_SERVER[‘REQUEST_URI’] : NULL ; $message = NULL; if ($uri AND strpos($uri,’edit.php’)) { if (strpos($uri,’post_type=page’)) { $message=”My custom message for page list”; } else { $message=”My custom message for post list”; … Read more