Thursday, March 23, 2023
  • Events
  • Interviews
  • Jobs
  • Opinion
  • Whitepapers
  • Podcasts
  • Web Hosting Directory
  • Login
  • Register
Cloud7 News
  • Cloud Computing
  • Web Hosting
  • Data Center
  • Linux
  • Cybersecurity
  • More
    • Software
    • Network/Internet
    • Hardware
    • Artificial Intelligence
    • Windows
    • Policy/Legislation
    • Blockchain
    • Troubleshooting
    • How-Tos
    • Articles
No Result
View All Result
Cloud7 News
  • Cloud Computing
  • Web Hosting
  • Data Center
  • Linux
  • Cybersecurity
  • More
    • Software
    • Network/Internet
    • Hardware
    • Artificial Intelligence
    • Windows
    • Policy/Legislation
    • Blockchain
    • Troubleshooting
    • How-Tos
    • Articles
No Result
View All Result
Cloud7 News
No Result
View All Result

Home > How-Tos > How to find the page ID in WordPress

How to find the page ID in WordPress

If you need to use the ID of the pages or other elements you have created in a WordPress website, this article can help you to find it.


Birol Bavas Birol Bavas
March 5, 2023
3 min read

To make it possible to access the data in the database, every element on your website has an ID value. With this ID, you can call, edit or delete your item. This makes it possible to perform the necessary operations to show your website to a visitor. In this article, we will explain how you can find the ID values of the elements without using plugins on your site.

Table of Contents

  • Finding the page ID without a plugin
  • Finding the tag or category IDs without a plugin
  • Examples of using the ID values in the codes
    • Code that prints the ID of the current page
    • A shortcode that lists the last five posts in the selected category

Finding the page ID without a plugin

If you want to find the ID value of a page in WordPress, first go to the Pages > All Pages tab.


Open the editing interface by clicking the Edit button on the page you want to know the ID value.


When you check the URL on the Edit page, the numeric value after the post= statement is the ID value of your page. As can be seen in the image below, the value of the Homepage page is 6.


Finding the tag or category IDs without a plugin

You can also use the above process for categories and tags. To find the tag ID value, go to Posts > Tags page.


In the list here, hover over the tag you want to learn and press the Edit button.


When you look at the URL of the page, the value next to tag_id= is the ID of your tag.


Examples of using the ID values in the codes

Code that prints the ID of the current page

You can add the following code to the relevant PHP file to print the ID of the current page on that page.

<?php echo get_queried_object_id(); ?>

A shortcode that lists the last five posts in the selected category

It is possible to access the posts in the category with their ID values. In the code example below, if you replace the 13 value in the $category_id variable with the desired category ID value, it will list the last 5 posts in that category.

Just add the code below to the functions.php file and save it. To use the code, you can use the shortcode on any page or widget you want.

function last_five_posts()
{
    $category = single_term_title("", false);
    $category_id = 13;
    $args = array(
        "numberposts" => 5,
        "category" => $category_id,
    );
    $posts = get_posts($args);
    $content = "";
    if( have_posts() ) {
        foreach($posts as $post){
            the_post();
            $link = get_permalink();
            $title = get_the_title();
            $content .= "<li><a href='$link' >$title</a></li>\n";
        }
    }
    return $content;
}
add_shortcode('last_five_posts', 'last_five_posts' );
Birol Bavas

Birol Bavas

Birol Bavas is the operations & security manager of Cloud7. He has been building system architectures for several years. He is also a PHP and C# developer and has built countless web applications. For more than 10 years, he has been using Linux actively.

Next Post
microsoft

Microsoft has a new solution against firmware attacks

Related News

How to change system language on Windows 11

How to change system language on Windows 11

March 22, 2023 7:00 pm
How to create and manage menus in WordPress

How to create and manage menus in WordPress

March 22, 2023 6:30 pm
Interview Tim Mackey, head of supply chain risk strategy of Synopsys

Interview: Tim Mackey, head of supply chain risk strategy of Synopsys

March 22, 2023 3:15 pm
7 richest domains and the reasons why

7 richest domains and the reasons why

March 22, 2023 2:45 pm
Get free daily newsletters from Cloud7 News Get the Cloud7 Newsletter
Select list(s):

Check your inbox or spam folder to confirm your subscription.

By subscribing, you agree to our
Copyright Policy and Privacy Policy

Get the free newsletter

Subscribe to receive the latest IT business updates straight to your inbox.

Select list(s):

Check your inbox or spam folder to confirm your subscription.

Recent News

  • How to change system language on Windows 11
  • How to create and manage menus in WordPress
  • Interview: Tim Mackey, head of supply chain risk strategy of Synopsys
  • 7 richest domains and the reasons why
  • CISA aims to identify vulnerabilities that attract ransomware

Cloud7 News
Cloud7 is a news source that publishes the latest news, reviews, comparisons, opinions, and exclusive interviews to help tech users of high-experience levels in the IT industry.

EXPLORE

  • Web Hosting
  • Cloud Computing
  • Data Center
  • Cybersecurity
  • Linux
  • Network/Internet
  • Software
  • Hardware
  • Artificial Intelligence
  • How-Tos
  • Troubleshooting

RESOURCES

  • Events
  • Interviews
  • Jobs
  • Opinion
  • Whitepapers
  • Podcasts
  • Web Hosting Directory

Get the Cloud7 Newsletter

Get FREE daily newsletters from Cloud7 delivering the latest news and reviews.

  • About Us
  • Privacy & Policy
  • Copyright Policy
  • Contact

© 2023, Cloud7 News. All rights reserved.

No Result
View All Result
  • Cloud Computing
  • Web Hosting
  • Data Center
  • Linux
  • Cybersecurity
  • More
    • Software
    • Network/Internet
    • Hardware
    • Artificial Intelligence
    • Windows
    • Policy/Legislation
    • Blockchain
    • Troubleshooting
    • How-Tos
    • Articles
  • Events
  • Interviews
  • Jobs
  • Opinion
  • Whitepapers
  • Podcasts
  • Web Hosting Directory

© 2023, Cloud7 News. All rights reserved.

Welcome Back!

Sign In with Facebook
Sign In with Google
Sign In with Linked In
OR

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Sign Up with Facebook
Sign Up with Google
Sign Up with Linked In
OR

Fill the forms below to register

*By registering into our website, you agree to the Terms & Conditions and Privacy Policy.
All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.