0

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.

This is the custom page and post url

0

basically 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

  • thank you very much, what i need is get post from url id – Abdelrhman ِAboelsaad Mar 13 '17 at 12:27
  • to query post $post_temp = get_post( $_GET['id'] ); $title = $post_temp->post_title; – Regolith Mar 14 '17 at 3:47
  • No it is inside in my file i just paste it here outside – Abdelrhman ِAboelsaad Mar 15 '17 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.