0

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.

1 Answer 1

0

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>";
2
  • 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? Commented May 12, 2013 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
    Commented May 13, 2013 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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