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

Does an article (post) id ever change?

No they don’t change, but you shouldn’t rely on them for external sites. If we’re talking about purely in the database on an individual WordPress site, then: If it’s a published/established post/page then yes, the ID will not change other than to delete it If its a revision, a draft, etc the ID won’t change, … Read more

How can I get the page url slug when ‘post_name’ returns an id?

Try this : $menu = get_term( $locations[$theme_location], ‘nav_menu’ ); $menu_items = wp_get_nav_menu_items($menu->term_id); foreach( $menu_items as $menu_item ) { $link = $menu_item->url; $title = $menu_item->title; $slug = basename($menu_item->url); } Pass the whole permalink to the basename function, which will automatically process the URL and give us only the slug.

Getting post id from wp_insert_post_data function?

In the following, ’10’ is the priority that my_func gets called and ‘2’ is the number of arguments that my_func accepts. The latter is important, since the add_filter function defines the default as 1, but the wp_insert_post_data filter hook sends two arguments. If you don’t set this as 2 you won’t get the second argument. … Read more