Good practical way to do loop within loop to show child custom type using a template code

I'm using Version WP e-Commerce plugin 3.8.12.1

I used a custom post type "event" with multiple value field "event_photos" and the field type is wpsc-product.

To show a single "event" use single-event.php :

?php while ( have_posts() ) : the_post(); ?
            ?php
                /* Include the single view for the event. 
                 */             
                include TEMPLATEPATH.'/event-templates/single.php';

            ?php endwhile; // end of the loop. ?

To show a list of products of a custom type "event" use "/event-templates/single.php" :

div class="entry-show-products"
            ?php $event_photos_obj = get_field('event_photos'); //Show product in a list
                    if( $event_photos_obj ) :
                        echo 'ul';
                        foreach ($event_photos_obj as $products) :
                            setup_postdata($products);?
                            li
                                ?php
                                $target_product = get_field('event_picture_photo', $products-ID);
                                ?
                                div class="imagecol"
                                    ?php 
                                        if ( wpsc_the_product_thumbnail(0,0,$products-ID) ) : ?
                                                a rel="?php echo wpsc_the_product_title(); ?" class="?php echo wpsc_the_product_image_link_classes(
                                                ); ?" href="?php echo esc_url( wpsc_the_product_image(0,0,$products-ID) ); ?"
                                                    img class="product_image" id="product_image_?php echo $products-ID ?" alt="?php echo wpsc_the_product_title(); ?" title="?php echo wpsc_the_product_title(); ?" src="?php echo wpsc_the_product_thumbnail(0,0,$products-ID); ?"/
                                                /a
                                    ?php endif; ?
                                /div!--close imagecol--
                            /li
                        ?php endforeach;
                        echo '/ul';
                    else :                  
                        echo "Δεν υπάρχει φωτογραφία";
                    endif; ?
        /div!-- .entry-show-photo --

My question is how to tell wp to index in a specific product and then using the template code "wpsc-single_product.php" :

    div id="single_product_page_container"

    ?php
        // Breadcrumbs
        wpsc_output_breadcrumbs();

        // Plugin hook for adding things to the top of the products page, like the live search
        do_action( 'wpsc_top_of_products_page' );
    ?

    div class="single_product_display group"
?php
        /**
         * Start the product loop here.
         * This is single products view, so there should be only one
         */

        ?
                    div class="imagecol"
                        ?php if ( wpsc_the_product_thumbnail() ) : ?
                                a rel="?php echo wpsc_the_product_title(); ?" class="?php echo wpsc_the_product_image_link_classes(); ?" href="?php echo esc_url( wpsc_the_product_image() ); ?"
                                    img class="product_image" id="product_image_?php echo wpsc_the_product_id(); ?" alt="?php echo wpsc_the_product_title(); ?" title="?php echo wpsc_the_product_title(); ?" src="?php echo wpsc_the_product_thumbnail(); ?"/
                                /a
                                ?php
                                if ( function_exists( 'gold_shpcrt_display_gallery' ) )
                                    echo gold_shpcrt_display_gallery( wpsc_the_product_id() );
                                ?
                        ?php else: ?
                                    a href="?php echo esc_url( wpsc_the_product_permalink() ); ?"
                                    img class="no-image" id="product_image_?php echo wpsc_the_product_id(); ?" alt="No Image" title="?php echo wpsc_the_product_title(); ?" src="?php echo WPSC_CORE_THEME_URL; ?wpsc-images/noimage.png" width="?php echo get_option('product_image_width'); ?" height="?php echo get_option('product_image_height'); ?" /
                                    /a
                        ?php endif; ?
                    /div!--close imagecol--


        /div!--close single_product_display--

        ?php echo wpsc_product_comments(); ?

?php do_action( 'wpsc_theme_footer' ); ?

/div!--close single_product_page_container--

Is it better way to use WP_Query?

Topic plugin-wp-e-commerce custom-field custom-post-types Wordpress

Category Web


<?php 
global $post;

  foreach ($event_photos_obj as $post) :

  ...
  ...
  // set up product in order to use native wordpress api
   setup_postdata($post);

 /* Include the single view for the product (photo). */
 include  .....


 endforeach;
 wp_reset_postdata();?>

my mistake my code is that setup_postdata with $product instead of $post as the tutorial said : https://codex.wordpress.org/Function_Reference/setup_postdata

This is one way, the second way uses WP_Query http://codex.wordpress.org/Class_Reference/WP_Query but in my case I don't need because I have already the object from the WP E-Commenrce with his functions and everything.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.