0

Please me!!!! Itried thow weeks and I search but without any result I can't save meta box that has both checkbox i need your help as soon as possible this is my code callback my metabox :

$terms = get_terms( 'type_livre', $terms = get_terms( 'type_livre', 
  array( 
  array(
`
<div>
<?php 
  $terms = get_terms( 'type_livre', 
  array(
        'orderby'    => 'id',
        'hide_empty' => 1 
    ) 
);

foreach( $terms as $term ) {


    $args = array(
        'post_type' => 'livre',
        'type_livre'  => $term->slug  taxonomy
    );
    $query = new WP_Query( $args );


    echo'<h2 class="h2 faq-cat">' . $term->name . '</h2>';



        while ( $query->have_posts() ) : $query->the_post(); ?>

            <input type="checkbox" name="check_list" id="<?php the_ID(); ?>" value="<?php the_title() ; ?>" >

            <label for="<?php the_ID(); ?>">
                <?php the_title() ; ?>
            </label>

            <label for="Qte_livre" style="margin-left: 352px;buttom">
                <?php echo 'Qte'; ?>
            </label>

            <input type="number" id="Qte_livre" name="Qte_livre" style="margin-left: 452px;"/>


        <?php endwhile;  wp_reset_postdata(); 

        echo '<hr/>';


    wp_reset_postdata();

} 
`
1
  • You said one thing your code said other thing. take time and explain little-bit more that make sense. however. I didn't find anything about metabox in your code and also you have using extra wp_reset_postdata()
    – mlimon
    Commented May 21, 2019 at 7:56

1 Answer 1

0

i don't know how can i save this metabox please helpe me. This Is my code :

<?php

function book_function_meta_box(){
 add_meta_box('book_meta_box', 'more Infos', 'book_meta_box_callback', 'book', 'normal');
}

add_action('add_meta_box', 'book_add_meta_box');


function book_meta_box_callback()
{
    wp_nonce_field('book_save_meta_box_data', 'book_nonce_name');

    $terms = get_terms(
        'category',
        array(
            'orderby'    => 'id',
            'hide_empty' => 1 // hide categories with no posts
        )
    );

    foreach ($terms as $term) {


        $args = array(
            'post_type' => 'book',
            'category'  => $term->slug
        );

        $query = new WP_Query($args);


        echo '<h2 class="h2 faq-cat">' . $term->name . '</h2>';

        while ($query->have_posts()) : $query->the_post();

            $livre_slug = sanitize_title_with_dashes(get_the_title(get_the_ID()));

            $qte_slug = $livre_slug . 'qte';

            ?>
            <div>

                <label for="<?php the_ID(); ?>">
                    <?php echo '<h1>' . the_title() . '</h1>'; ?>
                </label>
                <input type="checkbox" name="<?php echo $livre_slug; ?>" id="<?php the_ID(); ?>" value="<?php the_title(); ?>" <?php if (isset($_POST[$livre_slug])) echo 'checked="checked"'; ?> />

                <label for="<?php echo $qte_slug; ?>" style="margin-left: 352px;buttom">
                    <?php echo 'Qte'; ?>
                </label>

                <input type="number" id="<?php the_ID(); ?>" name="<?php echo $qte_slug; ?>" style="margin-left: 452px;" value="<?php echo esc_attr(get_post_meta(get_the_ID(), $qte_slug, true)); ?>" />

            </div>
            <?php



            wp_reset_postdata();
        endwhile;

        // use reset postdata to restore the original query
        wp_reset_postdata();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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