我编写了一个类,专门用于使用静态变量在小部件类之间传递数据,它也适用于您的用例。抓住课堂here.
对于每个自定义循环,您将使用以下方法:
$exclude_ids = IntermediaryData::get(); //Retrieve previous exclude IDs
$args[\'post__not_in\'] = $exclude_ids;
//new WP_Query($args); Custom loop query
//Loop Start
$exlude_ids[] = $post->ID,
//Loop End
IntermediaryData::set($exclude_ids); //Pass IDs to next loop