$posts = $GLOBALS['wpdb']->get_results("SELECT ID,post_content, post_title FROM wp_posts WHERE post_status = 'publish' AND post_type='post' LIMIT 1");
$permalink=get_permalink($posts[ID]);
$title=$posts[post_title];
$content=$posts[post_content];
$file = fopen("D://sam7.txt", "w");
fwrite($file,$permalink);
fclose($file);
$file = fopen("D://sam8.txt", "w");
fwrite($file,$title);
fclose($file);
我无法在sam8.txt中打印$ title,但$ permalink打印正常。 我怎样才能获得标题的价值。
答案 0 :(得分:0)
我认为你的语法有问题。请检查以下语法:
global $wpdb;
$results = $wpdb->get_results($wpdb->prepare("SELECT ID,post_content,post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' LIMIT 1;"));
$permalink = get_permalink( $results[0]->ID );
$title = $results[0]->post_title;
$content = $results[0]->post_content;
其余代码看起来很好。如果这对您有用,请告诉我。