How to get permalinks for individual posts using MySql query
-
This mysql query returns excerpts for the most recent 3 posts. When echoing the permalink, it links the most recent post to every single excerpt. How can I correctly link the associated permalink to each separate post?
‘ $sql = mysql_query(“SELECT * from wp_term_relationships where term_taxonomy_id = ‘3’ ORDER BY object_id DESC LIMIT 3 “);
while ($row = mysql_fetch_assoc($sql))
{
$object_id = $row[‘object_id’];
$sql_posts = mysql_query(“SELECT * From wp_posts where ID = ‘$object_id’ AND post_status = ‘publish’ AND post_type = ‘post’ ORDER BY ID DESC LIMIT 3”);
while($row_posts = mysql_fetch_assoc($sql_posts))
{?>
<div class=” gaming_news_col col-lg-4 col-md-4 col-sm-4″>
<h4>“><?php echo $row_posts[‘post_title’];?></h4>
<p><?php
$content = $row_posts[‘post_content’];
$post_content = myTruncate($content, 150, ” “);
echo $post_content;
?></p>
“>
</div>
<?php } ?>
<?php } ?>
‘
- The topic ‘How to get permalinks for individual posts using MySql query’ is closed to new replies.