PHP循环回显空白返回

时间:2018-03-23 04:01:24

标签: php mysql wordpress

我正在做一些后端Wordpress开发,并希望将guid永久链接与变量$post_number引用的特定值相关联。

目标是回显一系列guid链接,以便在页面上使用JavaScript / jQuery进行处理。问题是,目前我没有得到任何值,表明循环逻辑出现了问题,但我似乎无法确定问题所在。

<?php 
    $stmt2 = $pdo->query('SELECT * FROM wp_posts');
    $i = 1;
    //Variable $post_number is post_id from wp_postmeta.  The idea is to compare it to the post ID in the wp_posts database so I can get the post GUID
    while ($row = $stmt2->fetch()) {
        foreach ($post_number as $value){
            //Grab the guid for the post ID
            if($row['ID'] == $value[$i]) {        
                //get guid of the post and store in string
                $post_guid[] = $row['guid'];
            }
            else{}
            $i = $i + 1;
        }
    }
    echo "<input type='hidden' id='cover_post_guids' value='".json_encode($post_guid)."'>";
?>

0 个答案:

没有答案
相关问题