Ich versuche, den Post-Titel von SQL zu bekommen. Mein SQL-Code ist
$query ="SELECT wp_posts.post_title AS title ,
wp_posts.post_content AS content,
wp_posts.post_date AS blogdate
FROM wp_posts
WHERE wp_posts.post_status = 'publish'
ORDER BY wp_posts.post_date DESC ";
global $wpdb;
$result= $wpdb->get_results($query);
if ($result){
foreach($result as $post){
?><li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php echo $post->title; ?></a></li><?php
}
}else{
echo "Sorry, No Post Found.";
}
die();
Jetzt ist das Problem, dass ich Titel bekomme, aber the_permalink () nicht funktioniert.
Ich bin nicht sicher, warum Sie eine benutzerdefinierte Abfrage verwenden und nicht get_posts()
oder WP_Query
, wie Sie sollten.
Wie auch immer, Sie müssen die Post-ID bekommen ...
$query ="SELECT wp_posts.post_title AS title ,
wp_posts.post_content AS content,
wp_posts.post_date AS blogdate ,
wp_posts.ID AS ID
Und dann übergeben Sie diese ID einfach an get_permalink()
:
get_permalink( $post->ID );
Ähnliches gilt für das title-Attribut:
the_title_attribute( [ 'post' => $post->ID ] );