Advertisement
firoze

custom post query

Dec 18th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.94 KB | None | 0 0
  1. // For Post query that will support custom meta box & framework (this is custom post query). there are two code below you should use one
  2. <?php
  3. <?php if(!is_paged()) { ?>
  4. <?php
  5. $args = array( 'post_type' => 'sidebar_gallary2', 'posts_per_page' => -1 ); // thiscome from custom-posts.php
  6. $loop = new WP_Query( $args );
  7. ?>  
  8. <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
  9. <?php
  10. $price_name = get_post_meta( $post->ID, 'price_name', true ); // this id from cmb(example-functions.php)
  11. ?>
  12. <!---------------------------------------------------------->
  13. <?php the_post_thumbnail('sidebar_gallary2_img_size', array('class' => '')); ?> <!--here is our data--->
  14. <!----------------------------------------------------------->
  15.  <?php endwhile; ?>
  16. <?php wp_reset_query(); ?>
  17. <?php } ?>
  18. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  19. OR // we can use by this way also
  20. <div class="fix global_post">
  21.     <?php
  22.     global $post;
  23.     $args = array( 'posts_per_page' =>1, 'post_type'=> 'product_gallary' ); // thiscome from custom-posts.php
  24.     $myposts = get_posts( $args );
  25.     foreach( $myposts as $post ) : setup_postdata($post); ?>
  26.    
  27.     <?php
  28.     $price_name = get_post_meta( $post->ID, 'price_name', true ); // this id from cmb(example-functions.php)
  29.     $symble_name = get_post_meta( $post->ID, 'symble_name', true ); // this id from cmb(example-functions.php)
  30.     $symble = get_post_meta( $post->ID, 'symble', true ); // this id from cmb(example-functions.php)
  31.     $value = get_post_meta( $post->ID, 'value', true ); // this id from cmb(example-functions.php)
  32.     $product_code = get_post_meta( $post->ID, 'product_code', true ); // this id from cmb(example-functions.php)
  33.     ?>
  34.     <div class="single_post_price_code">
  35.     <?php if($price_name && $symble_name && $symble && $value && $product_code):?> <!---if more id exist for custom meta box---->
  36.     <p><?php echo $price_name;?>: <color><?php echo $symble_name;?> <?php echo $symble;?><?php echo $value;?></color></p>
  37.                 <code>COD: <?php echo $product_code;?></code>
  38.                                
  39.         <?php else:?>
  40.             <!--here is default <data--->
  41.                 <p>Price: <color>US $ 45</color></p>
  42.                 <code>COD:0111A</code>
  43.         <?php endif;?>
  44.     </div>
  45.             <?php endforeach;?>
  46. </div>
  47.  
  48.  
  49. //////////////////////////////////////// $args////////////////////////////////////////////////////////////////////////////////////////
  50. $args = array(
  51. 'post_type' => 'news_update', // thiscome from custom-posts.php
  52. 'posts_per_page' => 2,
  53. 'offset'           => 0,
  54. 'category'         => '',
  55. 'category_name'    => '',
  56. 'orderby'          => 'post_date',
  57. 'order'            => 'DESC',  // ASC OR  DESC  here ASC will show from previous post  and DESC will show from recent post
  58. 'include'          => '',
  59. 'exclude'          => '',
  60. 'meta_key'         => '',
  61. 'meta_value'       => '',
  62. 'post_mime_type'   => '',
  63. 'post_parent'      => '',
  64. 'post_status'      => 'publish',
  65. 'suppress_filters' => true
  66. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement