Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If someone puts a post on my site, they usually do that with some tags. If someone posts a post with the tag "hello", I want it to output that tag after my content and let it link to the archive page where it queries to see if there is another post with the same tag --> this already works!

What I now want is this: say there is also a post named "hello", now I want to get both the described tag above as well as a "see also [post] hello"... So I use the given tag as it does in default, but now I want to output the same tag again, but this time linking to the post with the same name... Is this possible? If so, how?

I tried editing the code that is given here: Redirect Tag to Post with the same name but I do not know how I can output the same tag, that does two different things.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You can use the get_page_by_title function as described by the codex here http://codex.wordpress.org/Function_Reference/get_page_by_title. Here is an example of getting the title of a post. By default, it's looking for a post type of 'page':

$current_post = get_page_by_title("certain title", OBJECT, "post");
echo "<a href='" . $current_post->guid . "'>{$current_post->post_title}</a>";
share|improve this answer
    
So if I understand correctly, it gets the title of a post... So what if I change post to tags and page with posts? Will that output the post if it has the same name as the tag? –  user1627363 May 12 '13 at 12:10
    
@user1627363: actually, had you read the codex I have linked, you would see that it returns a post object rather than post. That's why I'm able to use ->post_title to obtain its title later on. And I use "certain title" to show that you should replace the "certain title" with the name of your tag. –  Angela May 13 '13 at 2:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.