【问题标题】:Wordpress query to only include posts that have certain contentWordpress 查询仅包含具有特定内容的帖子
【发布时间】:2017-08-21 11:55:48
【问题描述】:

我希望此查询仅显示包含来自 geodir_special_offers echo 的文本的帖子

<?php

global $post;

$args = array( 

 'posts_per_page' => 4 , 'post_type' => 'gd_arts',);

$lastposts = get_posts( $args ); foreach ( $lastposts as $post ) : setup_postdata( $post ); ?>

<h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2>

<?php if ( has_post_thumbnail() ) { 
            the_post_thumbnail(array(486,226));
        } ?>
<php echo $post->geodir_special_offers; ?>

<?php endforeach; 
wp_reset_postdata(); 
?>

我对 WP 查询很陌生,所以请耐心等待。

如果不是 100% 结构化,请提前道歉。

【问题讨论】:

    标签: php wordpress posts


    【解决方案1】:

    试试这个!它会在回显内容之前检查是否设置了特别优惠。希望这就是您想要的。

    <?php
    
    global $post;
    
    $args = array( 
    
     'posts_per_page' => 4 , 'post_type' => 'gd_arts',);
    
    $lastposts = get_posts( $args ); 
    foreach ( $lastposts as $post ) {?>
    <?php if(strlen ($post->geodir_special_offers) > 5){ ?>
    <h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2>
    
    <?php if ( has_post_thumbnail() ) { 
                the_post_thumbnail(array(486,226));
            } 
    
        }
    }
    wp_reset_postdata(); 
    ?>
    

    【讨论】:

      猜你喜欢
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      相关资源
      最近更新 更多