get selected post using $_GET

时间:2011-10-11 作者:Jeremy Love

我试图获取帖子信息当我单击帖子上的按钮并使其与else函数中的信息相同时,我尝试添加一个查询,但作为回报,它使其回显所有帖子,而不是仅回显我单击的帖子

        <?php $cb_bp_x_points = cp_displayPoints($bp->loggedin_user->id,1,$return,0,$format);
$cp_bp_points_for_content = 100;
if ($cb_bp_x_points >= $cp_bp_points_for_content) :
global $post; 
if(isset($_GET[\'p\']) && $_GET[\'p\']==\'redeem\') { ?>

<div id="redeem">
<?php
$redeem_id = $prize_id;
$the_query = new WP_Query(\'post_type=prizes&p=\'.$redeem_id.\'&post_status=publish\');while ($the_query->have_posts()) : $the_query->the_post();
$post_redeem_id = get_post($redeem_id); 
$redeem_title = $post_redeem_id->post_title;
echo $redeem_title;

endwhile;

}else{
?>

<? $the_query = new WP_Query(\'post_type=prizes&showposts=16&post_status=publish\');while ($the_query->have_posts()) : $the_query->the_post();?>

<div class="prize-1 prize">
<?php $prize_id = the_ID();?>
<div><?php the_title(); ?></div>
<div><?php the_content(); ?></div>
<div><?php echo get_post_meta($post->ID, \'redeem_points\', true); ?></div>
<span><a href="?p=redeem">Redeem</a></span>
</div>

<?php endwhile; ?>

<?php }?>

<?php else : ?>

<p>You must login</p>

<?php endif; ?>
更新了我的代码以更好地理解。。。

2 个回复
最合适的回答,由SO网友:Jeremy Love 整理而成

嗯,这很有效。。。

$the_query = new WP_Query("post_type=prizes&p=".$redeem_id."&post_status=publish&p={$_GET[\'post_id\']}");while ($the_query->have_posts()) : $the_query->the_post();

<span><a href="?p=redeem&post_id=<?php echo $post->ID; ?>">Redeem</a></span>

SO网友:fuxia

不要使用reserved variable 作为GET(或POST)参数,这将不起作用。

结束

相关推荐

Query not returning CPT posts

哎哟,我的头撞到墙上了!我正在尝试在索引中查询我的帖子类型“clips”。php,但它只返回默认“post”中的post。我需要一些洞察力!我做错了什么?我的帖子类型:$args = array( \'labels\' => $labels, \'supports\' => $supports, \'hierarchical\' => false, \'menu_position\' => 4, \