Make slug as ID Number for custom post types

Here’s a way how to change the slug: add_action(‘wp_insert_post’, ‘change_slug’); function change_slug( $post_id ) { // Making sure this runs only when a ‘eduation’ post type is created $slug = ‘eduation’; if ( $slug != $_POST[‘post_type’] ) { return; } wp_update_post( array( ‘ID’ => $post_id, ‘post_name’ => $post_id // slug )); }

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

Get post / page ID from ACF Link field

The Page Link documentation actually shows how to retrieve the ID from a Page Link field. Just needed to do this myself and came across it. It worked well for me. <?php // vars $post_id = get_field(‘url’, false, false); // check if( $post_id ): ?> <a href=”https://wordpress.stackexchange.com/questions/304960/<?php echo get_the_permalink($post_id); ?>”><?php echo get_the_title($post_id); ?></a> <?php endif; … Read more

Fetch ID’s associated with a custom post type when translated with WPML?

NOTE: I’m not giving a full answer to your question but trying to give some snippets that may help in WPML-based project. I’ve used this function: function get_the_translated_ID($id){ if (!class_exists(‘sitepress’) return $id; global $sitepress; $type=get_post_type($id); return icl_object_id( $id, $type, false, $sitepress->get_default_language()); } This allows, for example, to search for custom_meta values of the original post … Read more

How can I receive the image id using the media box?

You can also add in a filter that can add the ID as a html5 data attribute to the returned HTML fragment from send_to_editor. public function image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt){ $dom = new DOMDocument(); @$dom->loadHTML($html); $x = new DOMXPath($dom); foreach($x->query(“//img”) as $node){ $node->setAttribute(“data-id”, $id); } if($dom->getElementsByTagName(“a”)->length == 0){ $newHtml = $dom->saveXML($dom->getElementsByTagName(‘img’)->item(0)); … Read more

How to get the post’s parent ID?

WordPress 5.7 introduces a new helper function to more easily fetch the parent post’s ID: get_post_parent() This can also be used in conjunction with has_post_parent(), so you could have something like looks like: <?php if ( has_post_parent() ) : ?> <a href=”<?php the_permalink( get_post_parent() ); ?>”> <?php echo sprintf( esc_html__( ‘Back to parent page: %s’, … Read more

get_users(…) only returns one user

The include key on get_users requires an array of IDs (numbers). You are giving it an array of objects that have an ID property. If you look at your first var dump you will see this. WP is casting that to a number and returning the user with that number which is not what you … Read more

Why ids in urls don’t work but slugs do?

Because the tag query variable expects the value to the terms slug. It’ll be looking for the term with slug ’15’ (which presumably doesn’t exist). And, yes its quite frustrating that wp_dropdown_categories() uses the ID as the value, rather than the slug. This is because it was originally used only for categories (for which IDs … Read more

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