Home Parsing content only storing one result
Reply: 0

Parsing content only storing one result

user2852
1#
user2852 Published in April 24, 2018, 6:36 am

I am having some issues getting my extremely messy code to submit data properly. Currently I am scraping a website which harbors many images and trying to collect them all and store them accordingly via my WordPress the_content selection.

Here's what I've got going so far, this is returning the images almost without any issues when I load it via a standard loop.

foreach ($html2->find('.entry-content img') as $image) {
    $imageurl  = $image->src;
    $new = '<img src="' . $imageurl . '" style="height: auto; width: 100%;margin-bottom: 3px;">';
    print  $thecontent = htmlspecialchars($new); print '<br>';
} foreach ($html2->find('iframe') as $video) {
    $videourl = $video->src;;
    $new = '<iframe src="' . $videourl . '" scrolling="no" frameborder="0" width="100%" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>';
    print  $thecontent = htmlspecialchars($new); print '<br>';
}

The above code will return something that looks like this containing 1 - how ever many images + videos we're trying to gather.

<img src="https://www.example.com/some-image-path-here.jpg" style="height: auto; width: 100%;margin-bottom: 3px;">
<img src="https://www.example.com/some-image-path-here.jpg" style="height: auto; width: 100%;margin-bottom: 3px;">
<img src="https://www.example.com/some-image-path-here.jpg" style="height: auto; width: 100%;margin-bottom: 3px;">
<img src="https://www.example.com/some-image-path-here.jpg" style="height: auto; width: 100%;margin-bottom: 3px;">

Now here's what I am using to try and upload the content to my WordPress site (everything except $content appears to be working properly.

$content = $thecontent;
$my_post = array(
    'post_title'    => wp_strip_all_tags( trim( $title ) ),
    'post_content'  => $content,
    'post_status'   => 'publish',
    'post_author'   => 2,
    'post_category' => array(2),
    'post_date' => date('Y-m-d H:i:s')
);
$post_id = wp_insert_post( $my_post );
remove_filter('content_save_pre', 'wp_filter_post_kses');
remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');

The above code returns the following within my WordPress the_content portion, which is the first image only, how can I make this work?

<img src="https://www.example.com/some-image-path-here.jpg" style="height: auto; width: 100%;margin-bottom: 3px;">

Note: The portion which is storing the WordPress data is being loaded inside of our initial parse loop, but outside of the loop which is collecting the images + videos.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.380287 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO