Please Help me passing variable

25 views
Skip to first unread message

BananaHead

unread,
Dec 26, 2009, 3:32:46 PM12/26/09
to phpQuery
Hi,

Im building a plugin with phpQuery and wordpress to scrape content, so
far so good!!

The thing is, I want to be able to pass $postid to the success1
function and I dunno how! Can anyone help?

HEre is my code:

<?

require_once('phpQuery/phpQuery.php');
//phpQuery::$debug = true;


$pq = phpQuery::browserGet('http://www.scraped.com', 'getPosts');

function getPosts($pq)
{

$posts = $pq['.post'];

foreach($posts as $post)
{


$postTitle = pq($post)->find(' a[rel="bookmark"]')->html();
$postBody = pq($post)->find('.content')->html();
$postUrl = pq($post)->find(' a[rel="bookmark"]')->attr('href');

// Create post object
$my_post = array();
$my_post['post_title'] = $postTitle;
$my_post['post_content'] = $postBody;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
//$my_post['post_category'] = array(8,39);

// Insert the post into the database
$postid = wp_insert_post( $my_post );


getComments($postUrl, $postid);


}

}


function getComments($postUrl, $postid)
{

$pq = phpQuery::browserGet($postUrl, 'success1'));

}

function success1($pq, $postid)
{

$comments = $pq['#thecomments > li'];

foreach($comments as $comment)
{

$author = pq($comment)->find('.name')->text();
$author_comment = pq($comment)->find('.content')->html();

$time = current_time('mysql', $gmt = 0);

$data = array(
'comment_post_ID' => $postid,
'comment_author' => $author,
'comment_content' => $author_comment,
'comment_date' => $time,
'comment_date_gmt' => $time,
'comment_approved' => 1,
);

wp_insert_comment($data);


}

}


?>

Reply all
Reply to author
Forward
0 new messages