So first I am trying to get all pictures from content to take first picture from content and set it as features image if such is not set. I found part of thi online, it seems that this makes loop somehow (i do not get it how actually)
array(1) {
[0]=>
array(4) {
[0]=> string(273) "whole image tag with alt"
[1]=> string(234) "whole image tag with alt"
[2]=> string(202) "whole image tag with alt"
[3]=> string(236) "whole image tag with alt"
}
}
So ... when i uncomment print_r($result); i do get an array that looks like this above. How to access first image tag? Maybe even access src or alt part of that tag? I tried to
echo $result[0];
but i got nothing. Why count is presenting 1 as answer and not 4?
global $wp_query;
$post = $wp_query->post;
$page_id = $post->ID; // page ID
$page_object = get_page( $page_id ); // page stuff
//$author_id = $post->post_author; // author ID
//$author_name = get_the_author_meta( 'display_name', $author_id);
$page_content = $page_object->post_content;
//first check all img tags in text
preg_match_all('/<img[^>]+>/i',$page_content, $result);
print_r($result);
echo count($result);