Custom Fields with get_post()

You already know the ID, so just use it: $customField = get_post_meta($my_id, “_mcf_customField”, true); But only for reference, if you want to get the ID from the object: $customField = get_post_meta($post_id->ID, “_mcf_customField”, true);

Cannot get grandparent object

just a small error. To get the parent and Grandparent objects, you need to get_post them also. The property “post_parent” only gives you the ID of that post, not the post_object itself. So you change your code like this: <?php $current = get_post($post->ID); //Conditional to be sure there is a parent if($current->post_parent){ $grandparent = get_post($current->post_parent); … Read more

WordPress function to get term or post object by id

get_queried_object() will get the currently queried ‘thing’ from the main query as an object. That could be a WP_Post, WP_Term, or WP_Post_Type (for post type archives) object, but I don’t think that’s quite what you’re asking for and wouldn’t be useful in AJAX. Other than that there isn’t a function for exactly what you’re asking … Read more

Disable block from editor based on post type

You can use the allowed_block_types hook: <?php function wpse_allowed_block_types($allowed_block_types, $post) { // Limit blocks in ‘post’ post type if($post->post_type == ‘post’) { // Return an array containing the allowed block types return array( ‘core/paragraph’, ‘core/heading’ ); } // Limit blocks in ‘page’ post type elseif($post->post_type == ‘page’) { return array( ‘core/list’ ); } // Allow … Read more

How to get the image EXIF date/time and use it for the WP post date/time

PHP has a function for this purpose: exif_read_data I used this image for testing. Try this code for your purpose: add_action( ‘add_attachment’, ‘create_post_from_image’ ); function create_post_from_image( $id ) { if ( wp_attachment_is_image( $id ) ) { $image = get_post( $id ); // Get image height/width for auto inserting the image later @list( $width, $height ) … Read more

What is an alternative to get_page_by_title()?

If you don’t force a title, and obviously do not know the id, the only way you can do it is by letting the user select which page to use, usually done in the theme’s options page, but can be done in the costumizer, or even as part of page editing

get_post() vs global $post or $GLOBAL[‘post’]

In essence, for all technical purposes, get_post() == $post == $GLOBALS[‘post’] As @tosho already explained in the linked post, $post === $GLOBALS[‘post’], so I will not go into that. What we are interested in is, how is get_post() the same. For this, we will need to look at the source code. As you can see, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)