coder500 Posted September 24, 2009 Share Posted September 24, 2009 Can someone help me to figure out how to compare title and category name of a wordpress post... For example if category name is "wordpress" and title is "Blogs with wordpress" I like to have an output "Match" Thank you Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 24, 2009 Share Posted September 24, 2009 if(str_pos($cat, $title)) { //match } Quote Link to comment Share on other sites More sharing options...
coder500 Posted September 24, 2009 Author Share Posted September 24, 2009 How we will get $cat and $title. In wordpress, the_category() prints category name and the_title() prints the title Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 24, 2009 Share Posted September 24, 2009 Hi coder500, $cat = the_category(); $title = the_title(); if(str_pos($cat, $title)) { //match } or: if(str_pos(the_category(), the_title())) { //match } Hope this helps. Quote Link to comment Share on other sites More sharing options...
coder500 Posted September 24, 2009 Author Share Posted September 24, 2009 No it did not work. It simply displayed category name and the title. I used strpos and not str_pos Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 24, 2009 Share Posted September 24, 2009 Hi coder500, Post the code you're using. Quote Link to comment Share on other sites More sharing options...
coder500 Posted September 24, 2009 Author Share Posted September 24, 2009 <?php if(strpos(the_category(), the_title())) { echo "match"; } ?> Quote Link to comment Share on other sites More sharing options...
coder500 Posted September 25, 2009 Author Share Posted September 25, 2009 I managed to fix it. If anyone comes through such a situation you can check this article http://worth2read.org/blog/2009/09/24/compare-title-and-category-name-in-wordpress/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.