Combine two custom post types
-
I’m a little stuck on the following use case, maybe someone here could give me a nudge in the right direction…
I’ve created a custom post type called Products. Inside the admin products can be created with the usual parts like featured image, a title and content. I display these products on the frontend via a template.
On the same frontend I display a Contact Form 7 form where visitors can make a bid on one of the products. After form submit a second custom post type with the name of Offers is created. Inside the admin I can view who made an offer on which product and what the amount of the offer is.Now, I want to display the highest offer inside each product. Maybe a written-out layout explains it a bit better. I’ve created a for/while loop which loops through the products and per product creates a div with:
[product title]
[product content: image & some text]
[highest offer: offer data from product] < how to get this data?I’m a little at a loss on how to accomplish this or if it’s even possible.
Any tips are appreciated.
Following is the code of my template so far:
<?php /** template name: homepage */ get_header(); ?> <div class="container"> <div class="row"> <div class="col-md-8"> <?php $productArgs = array( 'post_type' => 'products', 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'ASC' ); $products = new WP_Query($productArgs); if($products->have_posts()) { ?> <div class="products"> <?php while($products->have_posts()) : $products->the_post(); $productImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?> <div class="product"> <div class="row"> <div class="col-md-3"> <div class="product__image"> <?php if($productImage) { ?> <div style="background-image: url('<?= $productImage ?>');"></div> <?php } else { ?> <div style="background-image: url(<?php echo get_template_directory_uri() . '-child/images/no-image.jpg' ?>);"></div> <?php } ?> </div> </div> <div class="col-md-9"> <div class="product__content"> <p class="product__title"> <?= the_title(); ?> </p> <?= the_content(); ?> <div> Hoogste bod: </div> </div> </div> </div> </div> <?php endwhile; wp_reset_postdata(); ?> </div> <?php } else { ?> Geen producten gevonden <?php } ?> </div> <div class="col-md-4"> <?= do_shortcode( '[contact-form-7 id="15" title="Contact form 1"]' ); ?> </div> </div> </div> <?php get_footer();
The page I need help with: [log in to see the link]
- The topic ‘Combine two custom post types’ is closed to new replies.