显示最新帖子-如果“是”,选择为单选按钮值 [英] Show most recent post - if "yes" chosen as radio button value

查看:82
本文介绍了显示最新帖子-如果“是”,选择为单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的单选按钮的设置:

Here is the setup for my radio button:

我似乎无法

这是我的循环:

<?php
$args = array( 
   'numberposts'   => 1,
   'post_type'     => 'event',
   'posts_per_page' => '1',
   'meta_key'      => 'sponsored_event',
   'meta_value'    => 'yes'
   );
   $the_query = new WP_Query( $args );
?>    
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>        
<div class="sponsored-event">
<div class="sponsored-image" style="background-image: url(<?php the_field( 'event_image' ); ?>);"></div>
<div class="sponsored-info">
     <h2>Sponsored Event</h2>
     <h1><strong><?php the_title(); ?></strong></h1>
         <p><strong>Date</strong></p><br>
         <p class="place"><?php the_field( 'event_location' ); ?></p>
         <p class="time"><?php the_field( 'event_time' ); ?></p>
         <p><?php the_field( 'excerpt' ); ?></p>
         </div>
         </div>        
<?php endwhile; else: ?>
<?php endif; ?>


推荐答案

这对我有用:

<?php

$args = array(
    'post_type' => 'event',
    'showposts' => 1,
    'orderby' => 'date',
    'meta_query' => array(
            array(
            'key' => 'sponsored_event',
            'value' => 1,
            'compare' => 'LIKE'
            )
        )
    );

    $the_query = new WP_Query( $args );
?>

    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>


            <a href="<?php the_permalink(); ?>"><div class="sponsored-event">
                <div class="sponsored-image" style="background-image: url(<?php the_field( 'event_image' ); ?>);">
                </div>
                <div class="sponsored-info">
                    <h2>Sponsored Event</h2>
                    <h1><strong><?php the_title(); ?></strong></h1>
                    <p><strong>Date</strong></p><br>
                    <p class="place"><?php the_field( 'event_location' ); ?></p>
                    <p class="time"><?php the_field( 'event_time' ); ?></p>
                    <p><?php the_field( 'excerpt' ); ?></p>
                </div>
            </div></a>


    <?php endwhile; else: ?>

<?php endif; ?>

这篇关于显示最新帖子-如果“是”,选择为单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆