P
P
Pavel2020-05-21 18:41:45
WordPress
Pavel, 2020-05-21 18:41:45

How to get url by post_id in a loop?

I get the values ​​from the Wordpress database like this:

global $wpdb;
$world_table = $wpdb->get_results( "SELECT * FROM subjects " );
$content = '';
foreach ( $world_table as $item ) {
$content .=  " $item->post_id $item->subject "; 
}
return $content ;


Is it possible to get with this code not a post_id, but a link to a post with this post_id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-05-21
@shortcode

Links are not protected in the database, only the guid, the url is obtained like this
get_permalink($post_ID);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question