get_queried_object_id()
will return the ID of the current single post or page being viewed, as well as the static front page. For any type of archive page (except date, custom post type and home archives), the following will be returned:
-
Category ID of the category archive being viewed
-
Tag ID of the current tag archive being viewed
-
Author ID of the current author archive being viewed
-
Term ID for the current term page being viewed
If this is not the case in your case, you, your theme or a plugin you are using is in all probability using query_posts
somewhere. query_posts
breaks the main query object and resets the main query object to the custom query using query_posts
. This is why you should never ever ue query_posts
Related Posts:
- Get previously visited page ID
- ID for posts/blogs page
- Get ID of “root-page”
- Get users between user ids
- ID of Front-Page
- Always Encounter Using ID in WordPress as a Final Solution [closed]
- Why does the page/post ID keep growing when i refresh the post-new.php file?
- How can I exclude a specific ID from this line of code?
- get page id’s – not get pages?
- get post by nav id
- Ad units Div-ids frequently changing
- Consequence of the post auto incrementer off?
- Subcategory IDs in relation to parent category ID switch case
- add anchor tags rel to thumbnails id
- get_pages gives wrong ID for blogpage
- Get page ID of page that is set as the posts page
- How to get current page ID outside the loop?
- how to get page id of a page using page slug
- get post author id outside loop
- How to get Author ID outside the loop
- Custom Walker: how to get ID in function start_lvl
- How to get page title with the page ID?
- How to get permalink and title from post ID?
- How do I get the current edit page ID in the admin?
- Echo author ID in author.php
- Get page IDs from nav items
- How to get home page ID?
- Are post ID’s reliable?
- Get current post id in functions.php
- get all posts ID from a category
- How to obtain the user ID of the current profile being edited in WP-Admin?
- Creating a WordPress admin page without a menu for a plugin
- What is an alternative to get_page_by_title()?
- Settings API – creating reusable form elements?
- Get the current post ID as a variable in Javascript
- Is post ID number always incremental n+
- Can’t get post ID in functions.php?
- Get page id by title?
- How to add the category ID to admin page
- Post ID At The End Of Permalink URL Effects Performance (Positively)?
- Importing posts from old website to new conflicting post ID’s?
- Get All IDs Of A Post Type Using WP_Query
- Get user id from email?
- How to change WordPress user ID?
- How to get page’s ID if I know the title only?
- Getting the ID of a meta box
- Is there an equivalent of the PHP function sanitize_key in Gutenberg?
- Are all ID’s used unique?
- get all page IDs from wp_list_pages
- $post->ID displays wrong ID
- Add category to custom post type automatically, using category slug
- At my posts archive page, outside the loop, get_the_id() returns the top most post’s ID
- How to get any tag ID
- get_post_meta fields don’t show up on posts page
- Possible to create a new post and have the Title and Slug automatically use the post’s ID?
- Show ids of displayed media library items
- How do I display Youtube/Vimeo video ID on custom post type when user enters it in custom meta box?
- Showing random content / pictures from earlier posts in a sticky post?
- On Category page, How can I get the category ID?
- Get the post_id of a new post
- Get the comment author ID by the comment ID
- How to get ID of images used in gallery?
- get post id in while loops outputting page id
- How can I display a specific user’s first published post?
- get the_title_attribute by id
- Are Post IDs Unique Across all Post Types?
- Undefined variable post_id in custom quick edit coloumn
- Creating a Front-end based User Search
- Exclude main blog from get_blogs_of_user
- Does the menu item ID ever change?
- Get a post_id where meta_value equals something in a serialized meta_value field
- Return number of items in a table with post id
- How to get user_id from wordpress database inside ajax function?
- Get comment content by comment ID
- Get author ID with attachment ID
- Getting the wrong page ID
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- WordPress plugin Write User/staff ID as the same as the WordPress User ID
- get_attachment_id() only get id of first attached image after post update
- Get Post ID with insert/edit link
- URL scheme to retrieve tag archive by ID
- Passing the page ID to a login php script
- get menu id using its name
- How to create a link to jump to “Leave a comment” part?
- How can I get an array of all IDs from the current queried object?
- Getting post id from wp_insert_post_data function?
- How can I get the page url slug when ‘post_name’ returns an id?
- Does an article (post) id ever change?
- Why ids in urls don’t work but slugs do?
- get_users(…) only returns one user
- How to get the post’s parent ID?
- Can a page_id and a post_id be same?
- How can I receive the image id using the media box?
- Fetch ID’s associated with a custom post type when translated with WPML?
- Get post / page ID from ACF Link field
- Cannot get grandparent object
- Make slug as ID Number for custom post types
- Is there a better, more efficient way to get the post id outside the loop?
- post_author for wp_insert_attachment
- How to get category URL with the slug?