简体   繁体   English

Wordpress自定义循环根据日期显示帖子...可能吗?

[英]Wordpress custom loop displays posts based on the day…is posssible?

I would create a custom loop in the home page that will display only the posts that contains a specific word in its custom field.I'l try to explain it with an example. 我会在首页中创建一个自定义循环,该循环将仅在其自定义字段中显示包含特定单词的帖子。我将尝试通过一个示例进行解释。 EX. 例如 I got a website of a Basketball team and 2 custom post types called "COACh" and "TRAINING". 我有一个篮球队的网站和两个自定义职位类型,分别称为“ COACh”和“ TRAINING”。 In "COACH" i add the coach and its skills. 在“ COACH”中,我添加了教练及其技能。 In "TRAINING" i add the exrcise's name,the description and in the custom meta box i add the time,the coach,the duration and the day of the execution. 在“培训”中,添加锻炼的名称,说明,并在自定义元框中添加时间,教练,持续时间和执行日期。 Now,suppose that it's Monday i would display all the TRAININGS that contains the day Monday in its custom field. 现在,假设是星期一,我将在其自定义字段中显示包含星期一的所有TRAININGS。 Is it possible without a plugin like event calendar???? 没有事件日历之类的插件,有可能吗????

IS IT RIGHT? 这样对吗?

$today = date("l");
$args = array( 'post_type' => 'palinsesto', 'posts_per_page' => -1);
$palinsesto = get_posts( $args );
     foreach ( $training as $post ) {
               $day = get_post_meta( $post->ID, 'giorno ' ); // here day is key
            if($day==$today)
            while ($post->have_posts()) : $post->the_post(); ?>

Yes it is possible, I coded below roughly: 是的,有可能,我在下面大致编码:

$args = array( 'post_type' => 'TRAINING', 'posts_per_page' => -1); 
$training = get_posts( $args );

foreach ( $training as $post ) {
          $day = get_post_meta( $post->ID, 'day ' ); // here day is key
          if($day=='Monday')
            echo $post->post_title.'<br />';
            echo $post->post_content.'<br />';
}

this one is the solution for my question...it works great 这是我的问题的解决方案...效果很好

$today = strftime('%A'); 
$day = get_post_meta( $post->ID, 'giorno ' );
$my_query = new WP_Query(array(
                        'post_type' => 'palinsesto',
                        'meta_query' => array(
                                              array(
                                                    'key' => 'giorno',
                                                    'meta-value' => $value,
                                                    'value' => $today,
                                                    'compare' => '=',
                                                    ))));
if (have_posts()) :
    while ($my_query->have_posts()) : $my_query->the_post(); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM