Advertisement
designbymerovingi

List Posts For Sale

Mar 23rd, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. /**
  2.  * Show Posts For Sale
  3.  * Generates a list of posts that are set for sale using myCRED.
  4.  * @version 1.0
  5.  */
  6. add_shortcode( 'posts_for_sale', 'mycred_pro_show_posts_for_sale' );
  7. function mycred_pro_show_posts_for_sale( $atts, $content = '' ) {
  8.  
  9.     $args = array(
  10.         'post_type'    => 'post',
  11.         'post_status'  => 'publish',
  12.         'meta_query'   => array(
  13.             array(
  14.                 'key'     => 'myCRED_sell_content',
  15.                 'compare' => 'EXISTS'
  16.             ),
  17.             array(
  18.                 'key'     => 'myCRED_sell_content',
  19.                 'value'   => '"status";s:7:"enabled"',
  20.                 'compare' => 'LIKE'
  21.             )
  22.         )
  23.     );
  24.  
  25.     $for_sale = new WP_Query( $args );
  26.  
  27.     ob_start();
  28.  
  29.     if ( $for_sale->have_posts() ) {
  30.  
  31. ?>
  32. <ul>
  33. <?php
  34.  
  35.         while ( $for_sale->have_posts() ) {
  36.  
  37.             $for_sale->the_post();
  38.  
  39. ?>
  40.     <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  41. <?php
  42.  
  43.         }
  44.  
  45. ?>
  46. </ul>
  47. <?php
  48.  
  49.     }
  50.     else {
  51.  
  52. ?>
  53. <p>No posts are for sale at the moment.</p>
  54. <?php
  55.  
  56.     }
  57.  
  58.     $content = ob_get_contents();
  59.     ob_end_clean();
  60.  
  61.     wp_reset_postdata();
  62.  
  63.     return $content;
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement