Advertisement
salmancreation

custom post single page and query

Mar 1st, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1.  
  2. I'd recommend having the two groups of posts in different WordPress categories.
  3.  
  4. Then you can use get_posts to pull back the two different lists and print them out however you want.
  5.  
  6. After you created the CPT, do this for showing single posts of your CPT:
  7.  
  8. Duplicate the single.php file in your template and rename it like single-{post_type}.php (eg. single-movie.php)
  9. Flush the permalinks from WordPress
  10. You can get more details from this post
  11.  
  12. Now if you want to show a list of CPT you can use get_posts() with args:
  13.  
  14. $args = array(
  15. ...
  16. 'post_type' => 'movie'
  17. )
  18.  
  19. ----------------------------------------------------------
  20.  
  21.  
  22. <?php
  23.     //A rough example
  24.     $posts = get_posts(array(
  25.                'numberposts'   => 5,
  26.                'category_name' => 'custom-posts-2',
  27.                'orderby'       => 'post_date',
  28.                'order'         => 'DESC'
  29.              ));
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement