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 Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/ Share on other sites More sharing options...
Garethp Posted September 24, 2009 Share Posted September 24, 2009 if(str_pos($cat, $title)) { //match } Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-923979 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 Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-924105 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. Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-924114 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 Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-924127 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. Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-924130 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-924131 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/ Link to comment https://forums.phpfreaks.com/topic/175323-solved-compare-title-and-category-name-in-wordpress/#findComment-924637 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.