admin管理员组文章数量:1122832
I want to display the logo of a metadata from post-type for all post matching same name/category.
Posts-type: are Activities (sport). Posts: are News from these activities
Inside my first loop I get all post (default wp post) matching "carousel" category. Each post contain several categories but only one is use to compare, for example: "name-sport" . So for the first two posts I Have : Post1 cat -> carousel, website-name Post2 cat -> carousel, basketball
In the nested loop I get all post-type. All post-type name correspond to the name of sport. I get two value of these post type in a new array : post-name and metadata "logo".
I compare post category name with the name of post type.If these two values match I get the logo url
Also, I must add separately the logo of website for global news.
The in_array() function stop to work comparing the array of name and logo from post type.
For these two post, only the "website-name" logo is displayed
I think about a conflict between nested loop, but I can't find my mistake.
<?php
if($querynews->have_posts()) :
while ($querynews->have_posts()) :
$querynews->the_post();
$listcategories = get_the_category();
$cattocompare = array_column($listcategories, 'slug');
global $post;
$backup=$post; // Send data after inner loop
global $array_official_logo;
$array_official_logo = [];
$the_logo = "";
$query_sections = new WP_Query(array(
'post_type' => 'section_post_type',
'post_status' => 'publish',
'posts_per_page' => -1
));
while ($query_sections->have_posts()) :
$query_sections->the_post();
$post_id = get_the_ID();
array_push($array_official_logo, [
'name' => $post->post_name,
'logourl' => get_the_post_thumbnail_url()
]);
endwhile; //wp_reset_postdata();
$post=$backup;// Get back data from first loop
array_push($array_official_logo, [
'name' => 'website-name',
'logourl' => $uploadDir.'/official-logo-2024.png'
]);
foreach($array_official_logo as $keyS):
$the_logo = in_array($keyS['name'], $cattocompare) ? $keyS['logourl'] : "";
endforeach;
var_dump($the_logo);
?>
本文标签:
版权声明:本文标题:array - Inside nested wordpress loop (post & post-type) " in_array()" function can't retrieve 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736296368a1929777.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论