I need to create loop in wordpress custom page and this loop will display a content for post from custom category.
I create this page and get ID for this post, now i just need to make loop get this post from url ID.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communitybasically what you want to do is get the id from $_GET['id']
then you can use the WP_Query
<?php
wp_reset_postdata();
$args = array(
'category' => $_GET['id'],
'order' => 'DESC',
);
$query = new WP_Query($args);
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
//do your stuff here......................
endwhile; endif;
?>
here $_GET['id']
will get all the posts from category
If $_GET['id']
is a post ID and you have to retrive all the posts using that specific posts category then simply get the category id from that post by using
$category_detail=get_the_category( $_GET['id'] );
and then you can use the query like:
$args = array(
'category' => $category_detail,
'order' => 'DESC',
);
$query = new WP_Query($args);
hope this helps
$post_temp = get_post( $_GET['id'] ); $title = $post_temp->post_title;