如果字符串存在,请检查 the_content

Leo*_*das 1 php wordpress

这是情况。

我已经使用 Magento-Wordpress 集成设置了一个站点。集成有效,因此我可以从 wordpress 中调用任何我想要的 Magento 站点。

我想在产品页面中显示来自 wordpress 的帖子,其中包含一个特定的词。在我看来,我必须在帖子的 the_content() 中搜索产品的标题,然后带上我需要的 post_meta。

问题是我无法让它工作。我试过这个:

<?php $name_of_product = $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
<?php echo $name_of_product ; ?>
<?php   $args = array( 'post_type' => 'avada_portfolio', 'posts_per_page' => 103 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();           

    <?php  
        $pos = strpos( get_the_content(), "[Dominos]" );
        var_dump($pos);
        if ( ! (FALSE == $pos) ) {  
        the_content();  
        the_title(); 
        }
        else{echo ("NOTHING HERE");}
    echo '</div>';
    endwhile;                                       
?>
Run Code Online (Sandbox Code Playgroud)

但没有用。有什么建议?

rne*_*ius 5

根据您的var_dump()输出,您应该能够简单地使用:

if ( strpos( get_the_content(), '13801580' ) !== false) {
    the_content();  
    the_title(); 
}
Run Code Online (Sandbox Code Playgroud)