wordpress widget and post content issue

I am slightly stuck. The template i am using has a custom post type called products. When i add posts/pages here, i can get them displayed using a widget code in a page.

The widget displays the content entered into custom fields, but i can’t for the life of me work out how to modify the code in order to display the content from the custompost type Content section. Any insight?

Read More

This is the code from the shortcodes.php file which produces the widget.

   $count_posts = wp_count_posts('product');
    $published_posts = $count_posts->publish;
    $out ='';
    $out .=' <div class="pricing-table">';
        $out .= '<ul>';
        $counter = 0; 
        while ( have_posts() ) : the_post();
        $counter++;
        $product_price = get_post_meta($post->ID,'_product_price',true);
          $out .= '<li class="heading-column '.$class_heading.' color'.$counter.'">';
            $out .= '<h3>'.get_the_title().'</h3>';
            $out .= '<h5>';
            $out .= $currency ? $currency : "$";
            $out .= $product_price;
            if ($billing_cycle == "none") {
              $out .= ""; 
            } else {
              $out .= ' per '.$billing_cycle; 
            }
            $out .= '</h5>';
          $out .= '</li>';
        endwhile;
        $out .= '</ul>';  

        $out .= '<div class="clear"></div>';
        $out .= '<ul>';
        while ( have_posts() ) : the_post();
        $product_url = get_post_meta($post->ID,'_product_url',true);
        $product_feature = get_post_meta($post->ID,'_product_feature',true);
        $features_list = explode(",",$product_feature);
        $counter++;
          $out .= '<li class="pric-column '.$class_column;
          if ($counter%$columns==0) $out .= '-last';
          $out .= '">';
            foreach ($features_list as $flist) {
            $out .= '<ul class="feature-list">';
              $out .= '<li>'.$flist.'</li>';
            }
            $out .= '<li class="last">';
            $out .= '<a class="button" href="'.$product_url.'"><span>'.$product_button_text.'</span></a>';
            $out .= '</li>';
            $out .= '</ul>';  
      endwhile;wp_reset_query();
      $out .= '</ul>';  
  $out .= '</div>';

  return '[raw]'.$out.'[/raw]';
}

Related posts

Leave a Reply

1 comment

  1. your code doesn’t work because the loop doesn’t get filled.
    There for it will do the default loop of the page. (if it hasn’t run already that is)

    Also you do stuff that does nothing like $published_posts.

    You should create a custom loop with WP_Query.

    A little help to get you started:

    $query_args = array(
        'post_type' => 'products', // the post type name
        'post_status' => 'publish',
    );
    $products = new WP_Query ($query_args)
    
    // before loop stuff like opening tags
    while($products->have_posts()): $products->the_post();
        // do your stuff like display post_meta
    endwhile;
    // after loop stuff like closing tags
    

    This should get you started.
    If you need any help, let me know!