Viewing 9 replies - 1 through 9 (of 9 total)
  • I’ll guess you need to delete the Custom Field from each post that it was assigned.

    Or use phpMyAdmin to change it in wp_postmeta. Backup your database before attempting this approach.

    Your meta_key doesn’t actually have a : colon in it. But when you use get_post_meta to display your Custom Fields on a post, it will automatically write Your Key: Your Value. See, there is a colon showing then.
    https://codex.www.ads-software.com/Function_Reference/get_post_meta

    To work around this just change your theme’s single post template to display first Whatever Words you want as a label in place of The Key, (now here whatever punctuation or words you want), then a call for The Value using get_post_custom_values.

    https://codex.www.ads-software.com/Function_Reference/get_post_custom_values

    Let’s say you have the Custom field Key MY MOOD, and the Value is HAPPY.

    If you use get_post_meta, you’ll get:
    MY MOOD: HAPPY.

    Instead you want:
    My Current Mood is HAPPY.

    In your theme’s template put:

    My Current Mood is <?php get_post_custom_values(MY MOOD); ?>

    Hope this is what you’re looking for!

    Thread Starter matharchod

    (@matharchod)

    Dgold,

    Thanks for the detailed instructions! However, it seems strange that such a simple change requires such a weird workaround, no? The problem I have is that I still want to use the get_meta include put simply change the parameters a bit. Is there maybe a wp include file that I could edit?

    Again, thanks for the help!

    Thread Starter matharchod

    (@matharchod)

    Hi everyone,

    It seems I’ve found the answer to my question. Although both MichaelH and Dgold have great insight into the inner workings of WordPress, I have a simpler solution to my problem.

    The problem: How do I remove the colon : from the post-meta-key in my template?

    The (simple) answer:

    In the wordpress>wp-includes folder there is a file called “post-template.php”.

    Open that file in a text editor.

    Do a search in that file for this line of code:

    echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);

    Where is says $key:, simply remove the “:” colon.

    With this method, you can control your post-meta-key in all sorts of neat ways!

    Please remember subsequent WordPress updates may blow your change away!

    Thread Starter matharchod

    (@matharchod)

    That’s good point! I’ll make sure to keep an eye out for that. As a matter of fact, I’m going to suggest to the team in the Kvetch section to consider removing the “:” colon from the “post-template.php” doc. That way, users will be able to decide what comes after the meta-key when they enter the name of the key in the Admin panel.

    Thanks again!

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    The custom meta keys and values are used for much more than what you seem to think they are for, so I doubt very much that your idea will be considered.

    The way you’re doing it is actually more of a hack/workaround. The way I posted is using the built-in template tags. The way I showed can do everything that the other function can do, plus more flexibility. So if you need the default, use the easier code — if you are a power user of custom fields then try the codes I showed.

    So I think WP offers what you asked for out-of-the-box.

    You can hack the core files as you’ve done if that’s your preferred method. I’ve done it before and lived to regret it. When you upgrade WP, that change will be overwritten so you’ll have to keep doing it each new version of WP.

    The problem I’d see with your suggestion for WP to change this permanently is that 1000’s of people already use themes with the existing function, who want & expect the : colon to be there. People have been using this happily for years. We already have the option to display keys and values any way you wish, using the alternate code that I offered. It isn’t a bug, it’s a feature.

    The lingo “kvetch” refers to a complaint which is ignored, anyway. Kvetching means complaining into thin air. It’s infuriating that WP labels their suggestion box in that way, but that’s the way it is. Good luck out there.

    Thread Starter matharchod

    (@matharchod)

    Yeah guys, I see your points. It’s definitely not poetry, but it’s just plain easier for me to do. I’m not a power user, obviously, so you’ll have to forgive my preference for hacks. Or not. Thanks for the feedback, though.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How do I get rid of the colon : in my meta_key’ is closed to new replies.