我希望能够添加一个类,例如.samedate
共享相同内容的帖子meta_value_num
从自定义元框。
例如:
假设两篇文章对于输入的日期共享相同的自定义元框值2013/11/03
... 如果这两篇文章有相同的元数值,那么将类添加到这些文章中。
我希望能够添加一个类,例如.samedate
共享相同内容的帖子meta_value_num
从自定义元框。
例如:
假设两篇文章对于输入的日期共享相同的自定义元框值2013/11/03
... 如果这两篇文章有相同的元数值,那么将类添加到这些文章中。
add_filter(\'post_class\', function($classes){
global $wp_query;
static $meta = array();
// first call gathers meta values
if(!$meta)
foreach($wp_query->posts as $post)
$meta[$post->ID] = get_post_meta($post->ID, \'your_meta_key\', true);
// $wp_query->post should be the global (current) $post object
$this_meta = $meta[$wp_query->post->ID];
if($this_meta){
$counts = array_count_values($meta);
if($counts[$this_meta] > 1)
$classes[] = \'your_class\';
}
return $classes;
});
(未测试)我在设计自定义帖子的元框内容时遇到了一些困难。未应用CSS样式。根据我在另一篇帖子上读到的内容,我做了一个非常简单的测试。metabox创建:add_meta_box(\'wpptabs_company_details\', __(\'The Meta box name\', \'wpptabs\'), array(&$this, \'render_meta_content\'), \'wpptabs\', \'normal\', \'high\'); Meteabox含量:<la