what's wrong with this function - please please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
beachy
Forum Newbie
Posts: 2
Joined: Mon Jun 21, 2010 11:44 am

what's wrong with this function - please please help

Post by beachy »

Hi Everyone,
I need help with this inline post and categories plug-in. Originally by Aral Balkan but revised Ronny Welter.

Description: Allows you to include posts or categories in pages. This is simply done by using the syntax [[postid]] or [[cat:catid]].
The post id is working fine, but when I include a catid, it actually just pulls the 10 most recent posts from ALL categories. It's like it's not matching up the catid. Can you please take a look at this function???

Thank you! I really appreciate your help!!



//Added by Ronny Welter
//Get the [[cat:nnn]] tag from the post/page and get all posts in that category
//and add them in place to get them read by the includePosts function.
function includeCategoyPosts($content=''){

// Get the category IDs to include. Category IDs are in the form [[cat:nnn]].

preg_match_all('/(?<=\\[\\[cat\\:)[0-9]+(?=\\]\\])/', $content, $matches, PREG_PATTERN_ORDER);

$numCatMatches = count($matches[0]);

for ($i = 0; $i < $numCatMatches; $i++){//there might be different category includes, let's check them all
//

$allCatPosts=get_posts("numberposts=10&category=".$matches[0][$i]);
$numCatPosts = count($allCatPosts);
$thePostList='';

for ($j = 0; $j < $numCatPosts; $j++){//let's pot all the inline tags in there.
$thePostList .= "[[";
$thePostList .= $allCatPosts[$j]->ID;
$thePostList .= "]] \n";
}

//now let's put this part in the match in case
$content = str_replace("[[cat:".$matches[0][$i]."]]",$thePostList,$content);
}
//Ok, categories are replaced by the posts.
//Let's continue to Aral's function to put the posts in place.
return includePosts($content);
}

//
// Hooks
//

add_action('admin_menu', 'addAdminPage');
add_filter('the_content', 'includeCategoyPosts', 1);
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: what's wrong with this function - please please help

Post by cpetercarter »

Could be because you have misspelled "category" in this line:

Code: Select all

function includeCategoyPosts($content=''){
beachy
Forum Newbie
Posts: 2
Joined: Mon Jun 21, 2010 11:44 am

Re: what's wrong with this function - please please help

Post by beachy »

Thanks cpetercarter, I did try that to both instances they were used and I still get the same thing. I can send the whole code if that will help, it's pretty short, about 4 functions. But I think it's within this function since the original part of the code works with no problem.
Thanks again!
Post Reply