0

I want to save every query result inside a new td in this tr, but somehow it didn't work. I also made <?php wp_reset_postdata();?> at the end of the table. It gives me HTTP 500 Error.

<tr>
                    <td>
                        <?php echo "Levesek" ?>
                    </td>
                    <?php
                    $args3 = array(
                      'post_type' => 'etlap',
                      'post__in' => $ids,);

                    $query3 = new WP_Query( $args3 );
                    ?>
                    <?php if ($query3->have_posts()): ?>
                        <?php while($query3->have_posts()): ?>
                            <?php $query3->the_post();?>
                                <?php $levesek = get_field('levesek'); ?>
                                    <?php if($levesek): ?>
                                        <?php foreach ($levesek as $leves): ?>
                                            <?php setup_postdata($leves)?>
                    <td><?php echo $leves->post_title;?></td>
                                        <?php endforeach;?>
                                    <?php endif;?>
                        <?php endwhile; ?>
                    <?php endif;?>
                </tr>
4
  • what is the result of the code? what is the content of the array $ids? you have $query3 but you are using $args2 - did you mean to use $args3 ?
    – Michael
    Dec 26 '17 at 21:37
  • Changed to $args3 but I have a same problem
    – DeluxeD
    Dec 26 '17 at 21:41
  • what is the result? what is the content of $ids?
    – Michael
    Dec 26 '17 at 21:48
  • http 500 error. Well now I just only use 'post_type' => 'etlap' as array.
    – DeluxeD
    Dec 26 '17 at 21:58
0

Okay, I fixed it. The final code is:

        <?php
    $args2 = array('post_type' => 'etlap',
        'posts_per_page' => 5,
        'post__in' => $ids,
        'order' => 'post__in');

    $query2 = new WP_Query($args2);
    ?>
                <tr>
                <td>
                    <?php echo "Levesek" ?>
                </td>
                <?php if ($query2->have_posts()): ?>
                    <?php while ($query2->have_posts()): ?>
                        <?php $query2->the_post(); ?>
                        <td>
                            <?php
                            $levesek = get_field('levesek');
                            $leves_adag = get_field('leves_adag');
                            ?>
                            <?php if ($levesek): ?>
                                <?php foreach ($levesek as $leves): ?>
                                    <?php setup_postdata($leves); ?>
                                    <?php echo $leves->post_title; ?>
                                    <?php $description = do_shortcode('[woo-product-shortcodes id="' . $leves->ID . '" data_attribute="short_description"]'); ?>
                                    <br><?php echo $description; ?>
                                <?php endforeach; ?>
                            <?php endif; ?>
                            <?php if ($leves_adag == 0): ?>
                                <br><?php echo "Elfogyott"; ?>
                            <?php endif; ?>
                            <?php if ($leves_adag != 0): ?>
                                <br><?php echo $leves_adag; ?>
                                <?php $product = new WC_Product('.$leves->ID.'); ?>
                                <?php if ($product->is_type('simple')): ?>
                                    <br><?php echo "Szipla (vásárlás beillesztése folyamatban)"; ?>
                                <?php endif; ?>
                                <?php if ($product->is_type('variable')): ?>
                                    <br><?php echo "Variálható (vásárlás beillesztése folyamatban)"; ?>
                                <?php endif; ?>
                            <?php endif; ?>
                            <?php wp_reset_postdata(); ?>
                        </td>
                    <?php endwhile; ?>
                <?php endif; ?>
            </tr>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.