我对这件事感到非常困惑,不知道是否有人能告诉我哪里出了问题。
我正在为查询的结果帖子获取一些authormeta,我想统计某些authormeta在这些结果中重复的次数。
E、 g.有10个“配方”帖子>;每个帖子的作者(每个帖子不同)都有一个“最喜欢的食物”元项目>;我希望结果类似于;3位食谱作者将“馅饼”作为他们最喜欢的食物;。
这是我到目前为止所做的,这让我很接近,但我需要$authorfood的结果用于$text,但它似乎只适用于纯文本语句?
$the_query = new WP_Query( array( \'post_type\' => \'recipe\', \'posts_per_page\' => -1 ) );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
$the_query->the_post();
$authorfood = get_the_author_meta( \'favourite_food\' ); // the result of this is the plain list I want to use later, e.g. "appleappleappleapplebananapiepiepie"
$text = "Plain text to count frequency of words"; // this needs to be the result of $authorfood above
$words = str_word_count($text, 1);
$word_frequencies = array_count_values($words);
arsort($word_frequencies);
print_r($word_frequencies);
endwhile;
endif;
我可能是完全错了。很抱歉问了这么愚蠢的问题,但我已经搜索了又搜索,找不到答案。你知道我如何统计“食谱作者”最喜欢的食物的数量吗(必须是那些帖子作者,而不是网站上的所有作者,因为有多种帖子类型)?