开发者

Wordpress get ID - not displaying

I am hoping that someone can help me with this relative simple problem:

 <?php $idairports = the_ID(); ?>

$liveposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM wp_airports WHERE id = ".$ida开发者_StackOverflow中文版irports."") );

It seems like I am not able to get the variable passed into the sting above.

$idairports is supposed to be a numeric value...

If I do this <?php echo $idairports ?> I do get the value.

But I do not get the value here FROM wp_airports WHERE id = ".$idairports.""

What am I doing wrong

Thanks

Okay I have found the main problem:

global $wpdb;
$page_object = $wp_query->get_queried_object();
$page_id = $wp_query->get_queried_object_id();
$idairports = $page_id;

It seems like I were getting the_ID(); value the wrong way...

If I get the page_id as above, it works 100%

Can someone maybe explain why the_ID() would work if I echo the_ID() outside the MYSQL statement...


Your quotes are screwed up and your php tags look awkward:

<?php 
    $idairports = the_ID();
    $liveposts = $wpdb->get_results($wpdb->prepare('SELECT * FROM wp_airports WHERE id = ' . $idairports));
?>


I think your issue is with the double quotes. Try removing the quotes when referencing the id like this.

$liveposts = $wpdb->get_results( $wpdb->prepare('SELECT * FROM wp_airports WHERE id = ' . $idairports) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜