事件自定义帖子类型的快捷码顺序

时间:2015-01-14 作者:frenchy black

好的,我在一个网站上使用post-type-event和post\\u-meta-event\\u-start\\u-date,我创建了一个快捷码,除了按顺序显示外,所有内容都显示得很好,似乎没有使用meta\\u键或meta\\u值来显示。这是页面http://mixedbagnext.com/wordpress/events/ 您会注意到日期顺序错误,我希望它首先显示最近的日期,然后显示后面的其他日期。旁注im使用更多字段插件创建post\\u meta,并设置为2015年1月1日输入的日期。这是我的密码

    // SHORTCODE event
function event_shortcode( $atts ) {
extract( shortcode_atts( array( \'limit\' => -1, \'type\' => \'event\'), $atts ) );   

$eventlist = \'\';

$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1;  

$carousel_query = new WP_Query(array ( 
    \'posts_per_page\' => $limit, 
    \'post_type\' => $type, 
    \'post_status\'  =>  \'publish\',
    \'order\' => \'DESC\',
    \'orderby\' => \'meta_value_num\',
    \'meta_key\' => \'event_start_date\',
    \'meta_query\' => array(
   // \'relation\'  =>   \'AND\',
    array(
            \'key\' => \'event_start_date\',
         \'value\' => date(\'Y-m-d\', strtotime(\'-6 hours\')), //value of "order-date"
         \'compare\' => \'>=\', //show events greater than or equal to today
         \'type\' => \'CHAR\'
        )
    ),
    \'paged\' => $paged ));

if ($carousel_query->have_posts()) :

$eventlist .= \'<ul class="event-list clearfix">\';

while ($carousel_query->have_posts()) : $carousel_query->the_post();

$event_artist = wp_strip_all_tags( get_the_term_list( get_the_ID(), \'artist_event\', \' \', \' , \', \' \') );

$event_start_date = get_post_meta(get_the_ID(), \'event_start_date\', true );
$fixed_date_day = strtotime($event_start_date);
$fixed_date_month = strtotime($event_start_date); 
$event_start_time = get_post_meta(get_the_ID(), \'event_start_time\', true );

$fixed_time_start = strtotime($event_start_time); 

$event_end_date = get_post_meta(get_the_ID(), \'event_end_date\', true );
$event_end_time = get_post_meta(get_the_ID(), \'event_end_time\', true );

$fixed_time_end = strtotime($event_end_time); 

$event_location = get_post_meta(get_the_ID(), \'event_location\', true );
$event_address = get_post_meta(get_the_ID(), \'event_address\', true );
$event_city = get_post_meta(get_the_ID(), \'event_city\', true );
$event_state = get_post_meta(get_the_ID(), \'event_state\', true );
$event_zipcode = get_post_meta(get_the_ID(), \'event_zipcode\', true );
$event_telephone = get_post_meta(get_the_ID(), \'event_telephone\', true );
$event_website = get_post_meta(get_the_ID(), \'event_website\', true );
$event_description = get_post_meta(get_the_ID(), \'event_description\', true );
$event_url = get_post_meta(get_the_ID(), \'event_url\', true );
$event_button = get_post_meta(get_the_ID(), \'event_button\', true );
$event_btn_img = get_post_meta(get_the_ID(), \'event_btn_img\', true );
$event_price = get_post_meta(get_the_ID(), \'event_price\', true );

$eventlist .= \'<li id="event-list-\'. get_the_ID() .\'" class="\' . implode(\' \', get_post_class(\'clearfix\')) . \'" >\'

.\'<div class="event-list-date">\'
.\'<span class="event-list-day">\'.date(\'d\' , $fixed_date_day) .\'</span>\'
.\'<span class="event-list-month">\'.date(\'M\' , $fixed_date_month) .\'</span>\'
.\'</div>\'
.\'<div class="event-list-title">\' . get_the_title() . \'</div>\'
.\'<div class="event-list-time"><span class="yellow-text">time:</span>\'.date(\'g:i A\' , $fixed_time_start) .\'</div>\'
.\'<div class="event-list-artist"><span class="yellow-text">with:</span>\'.$event_artist.\'</div>\'
.\'<div class="event-list-location"><span class="yellow-text">location:</span>\'.$event_city.\', \'.$event_state.\'</div>\'
.\'<div class="event-list-link"><a href="\'.$event_url.\'" target="_blank">more info</a></div>\'
.\'</li>\';

endwhile;
$eventlist .= \'</ul>\';
endif;
wp_reset_query();

return $eventlist;

}
add_shortcode( \'event\', \'event_shortcode\' );
// the shortcode -> [event limit="5"]

1 个回复
SO网友:frenchy black

我想出来了。对于任何需要找到此解决方案的人,我编辑了上述代码。我更改了:

\'order\' => \'DESC\'

\'order\' => \'ASC\'
\'orderby\' => \'meta_value_num\'

\'orderby\' => \'meta_value\'

来实现我想要的秩序。

结束

相关推荐

Multiple level shortcodes

我正在开发一个插件,遇到了一种情况,我希望有人能帮我找到一个解决方案。我想要一个短代码结构,如:[shortcode_1] [shortcode_2] [shortcode_3] [shortcode_4][/shortcode_4] [/shortcode_3] [/shortcode_2] [/shortcode_1] 但如果我使用add\\u短代码,只有第一个短代码有效。。。有没有办法得到这样的短代码结构?谢谢