Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

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

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:21:06+00:00 2026-06-10T21:21:06+00:00

I was coding a simple metabox for wordpress and have a little issue when

  • 0

I was coding a simple metabox for wordpress and have a little issue when saving data.

The meta box is in my “create article”-page has two textfields. These are saved as post-meta, when the post is saved.

While saving I check if the fields were filled – if they are empty I take the post title and extract the data I need. The idea is to take everything that is before the first “-“. If there is no minus sign, the whole title should be saved in my custom field. Now, this fails to find “-” in the title (alltough there is one) and returns the whole title every time:

function get_from_title($title) {
  $pos = strpos($title, '-');

  if ($pos) {
    return trim(substr($title, $pos));
  }
  else {
    $pos = strpos($title, '–'); //added this since two different signs could be used

    if ($pos) {
      return trim(substr($title, $pos));
    }
    else {
      return $title;
    }
  }
}

the function that is calling get_from_title is getting the title via get_the_title( $post_id ) and this works without problems.

Is wordpress encoding the title somehow? Why can’t strpos find the minus sign? What should I look for instead?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:21:08+00:00Added an answer on June 10, 2026 at 9:21 pm

    I replied to the thread you started on this topic in the WordPress forums. You can find your answer there.

    Alternatively, here’s what I said. 🙂

    Ah yes. This is a tricky one. So, why can’t strpos find a hyphen in
    the title when clearly we can see one? Because there isn’t one. hehe.

    What WordPress is doing here is converting your hyphen ( minus sign )
    into an en-dash.

    This will give you diddly-squat:
    $pos = strpos( $title, '-' );

    You want this:
    $pos = strpos( $title, '–' );

    Let me know how things turned out for you. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm coding a simple little class with a single method send an email. My
I'm coding a simple websocket server on netty. Before a client connection has been
I'm coding a simple roguelike game in C++ using SDL library, and I have
I have a simple form that passes to an ASPX page to watch a
I'm coding a simple text game to learn ruby. The hash has to be
I have this simple piece of coding in my Homecontroller.cs, but I receive the
I know its extremely simple, but I have been coding all day and it
I am coding simple 404 seo for my website. I am little confused at
I am currently coding a simple Data Access Layer, and I was wondering which
I'm coding a simple graphics program in Java. So, I have 3 classes. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.