Sign Up

Captcha Click on image to update the captcha.

Have an account? Sign In Now

Sign In

Discover the power of expert communities in searching for solutions.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question. Please subscribe to paid membership

Forgot Password?

Don't have account, Sign Up Here
Please subscribe to paid membership

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

GetSolu.com

GetSolu.com Logo GetSolu.com Logo

GetSolu.com Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Problems/Q 4047
Next
Need More Solution
Anonymous
  • 0
Anonymous
Asked: April 5, 20232023-04-05T07:56:27+00:00 2023-04-05T07:56:27+00:00In: Website Development

How to get WordPress page URL by title without using deprecated function or WP_Query class?

  • 0

I am working on a WordPress project and I need to get the page URL by the title of the page. I used to use the function get_page_by_title ($article [‘title’], OBJECT, ‘post’) to do this, but I found out that this function has been deprecated and is no longer recommended. This function was very convenient for me because I was testing some features on different databases and I could not use IDs to get the page URL. Is there any alternative way to get the page URL by the title of the page in WordPress without using IDs or WP_Query class? I think using WP_Query class is too complicated and inefficient for this simple task. I would appreciate any suggestions or solutions that can help me with this problem. Thank you.

wordpress
  • 1 1 Solution
  • 25 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Solution

    • Voted
    • Oldest
    • Recent
    1. Mr. Zero
      2023-04-05T07:58:08+00:00Added an answer on April 5, 2023 at 7:58 am

      One possible way to get the page URL by the title of the page in WordPress without using IDs or WP_Query class is to use the function get_page_link_by_title ($title). This function takes the title of the page as a parameter and returns the URL of the page if it exists, or false if it does not. The function uses the global $wpdb object to query the database and get the ID of the page by its title, then uses the function get_permalink ($id) to get the URL of the page by its ID. Here is an example of how to use this function:

      function get_page_link_by_title ($title) {
      global $wpdb;
      $id = $wpdb->get_var (“SELECT ID FROM $wpdb->posts WHERE post_title = ‘$title’ AND post_type = ‘page'”);
      if ($id) {
      return get_permalink ($id);
      } else {
      return false;
      }
      }

      // Usage example
      $page_title = “About Us”;
      $page_url = get_page_link_by_title ($page_title);
      if ($page_url) {
      echo “The URL of the page ‘$page_title’ is $page_url”;
      } else {
      echo “The page ‘$page_title’ does not exist”;
      }

      I hope this function helps you with your WordPress project. Please note that this function does not sanitize the title parameter, so you should make sure that it does not contain any malicious or invalid characters before passing it to the function. Also, this function assumes that there is only one page with the given title in the database, so it may not work correctly if there are duplicate titles. You may want to modify the function to handle these cases according to your needs.

      • 0
      • Share
        Share
        • Share onFacebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Add Your Problem

    Stats

    • Problems 31
    • Solutions 39
    • Best Solutions 5
    • Users 72
    • Popular
    • Solutions
    • Anonymous

      Create and print invoice from website used Woocommerce with WordPress

      • 2 Solutions
    • Anonymous

      Need show post by timeline on my blog website

      • 2 Solutions
    • Anonymous

      I want to find a software collage of photos with ...

      • 2 Solutions
    • Anonymous

      How to hide products that ware sold out in woocommerce?

      • 2 Solutions
    • Anonymous

      SMTP Error: Could not authenticate. Zoho mail

      • 2 Solutions
    • Mr. Zero
      Mr. Zero added an answer The future may seem uncertain and project progress could potentially… April 20, 2023 at 3:23 pm
    • Mr. Zero
      Mr. Zero added an answer One possible solution to your problem is to use the… April 5, 2023 at 8:06 am
    • Mr. Zero
      Mr. Zero added an answer One possible way to get the page URL by the… April 5, 2023 at 7:58 am
    • Mr. Zero
      Mr. Zero added an answer One possible reason why your custom font is not loading… April 5, 2023 at 7:49 am
    • Mr. Zero
      Mr. Zero added an answer The problem with your current query is that you are… April 5, 2023 at 7:42 am

    Top Members

    Pemberton Lockwood

    Pemberton Lockwood

    • 0 Problems
    • 4 Solutions
    Master
    Idris Rhiannon

    Idris Rhiannon

    • 0 Problems
    • 3 Solutions
    Master
    Kevin Hernandez

    Kevin Hernandez

    • 0 Problems
    • 2 Solutions
    Master

    Trending Tags

    affiliate marketing ai career development freelance job income generation paywall profitable website startup woocommerce wordpress

    Explore

    • Home
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges

    Footer

    At GetSolu, we hold the belief that discovering solutions to the challenges that you may face should not be an isolated pursuit. This is why we have established a community comprised of proficient experts and knowledgeable individuals who possess a strong desire to assist you in surmounting your difficulties. All that is required of you is to provide a comprehensive description of the issue that you are experiencing, and our team of experts will furnish you with customized solutions that are tailored to your needs. Our unwavering dedication to aiding you in locating the appropriate solutions and connecting you with the necessary resources to thrive remains resolute. There is no need to hesitate. Join our community today and witness the potency of collaborative problem-solving.

    • Terms of Service
    • Privacy Policy

    Follow

    © 2023 Get Solu. All Rights Reserved
    With Love by Mr. Zero.