I have a snippet of code that I have been trying to learn how it functions so that I can modify it to pull in related posts by tags instead of categories. I am hoping someone can teach me what to do.
function get_related_posts($postdata)
{
$postCatArr = wp_get_post_categories( $postdata->ID );
$post_array = array();
for($c=0;$c<count($postCatArr);$c++)
{
$category_posts=get_posts('category='.$postCatArr[$c]);
foreach($category_posts as $post)
{
if($post->ID != $postdata->ID)
{
$post_array[$post->ID] = $post;
}
}
}
if($post_array)
{
?>
I looked up most of the functions but some I didn't understand what the code is telling WP what to do, like: if($post->ID != $postdata->ID) and for($c=0;$c<count($postCatArr);$c++).
Can anyone shed some light on what I need done so that I can learn to make modifications easier?
Thank you!