0

I am using the below function in my custom theme to load posts via AJAX. But for some reason it is breaking the WP ADMIN WIdget Drag and Drop and also showing the White Screen of Death when I uploaded the theme to a live server.

I can't figure out what is wrong I am doing. I have no white spaces on my fucntions.php

<?php
function mm_get_all_informations() {
?>

    <table class="table results">
        <thead>
            <tr>
                <th width="19%">Bank Name</th>
                <th width="21%">Nature of Loans &amp; Advances</th>
                <th width="13%">Years</th>
                <th width="21%">Loan Category</th>
                <th width="8%">EMI</th>
                <th width="17%">Total Amount Payable</th>
                <th width="14%">Interest Rate %</th>
                <th width="8%"></th>                                      
            </tr>
        </thead>
        <tbody>




    <?php
    /* the query */


    //$current_category = single_cat_title("", false);
    $current_category = $_POST['category'];
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $bc_args = array(
        // 'offset'=>2,
        'post_type' => 'data',
        'data-category' => $current_category,
            // 'order' => 'DESC',
            //  'meta_key' => 'interest_rate',
            //  'orderby' => 'meta_value_num',
            //'paged' => $paged,
            //'posts_per_page' => 1,
    );



    $sortedPosts = new WP_Query($bc_args);



    $mm_page_no = 1;
    $mm_count = 3;
    $pagination_no = 1;
    $pagination.='<ul id="pagination" class="pagination"> <li class="disabled"><a href="#">«</a></li>';
    $pagination.='<li><a  class="info_link" href=#info-' . $mm_page_no . '>' . $pagination_no++ . '</a></li>';
    ?>
            <?php while ($sortedPosts->have_posts()) : $sortedPosts->the_post(); ?>

                <?php
                $company_name = get_post_meta(get_the_ID(), 'mm_s_bank_name', '$single', true);
                $cat_meta = get_post_meta(get_the_ID(), 'mm_s_category', '$single', true);
                //$condition = get_post_meta(get_the_ID(), 'mm_s_condition', '$single',true);
                $emi = get_post_meta(get_the_ID(), 'mm_s_emi', '$single', true);
                $total_amount_payable = get_post_meta(get_the_ID(), 'mm_s_tap', '$single', true);
                $interest_rate = get_post_meta(get_the_ID(), 'mm_s_i_rate', '$single', true);


                $loan_amount = get_post_meta(get_the_ID(), 'mm_s_loan_amount', '$single', true);
                $loan_amount_max = get_post_meta(get_the_ID(), 'maximum _loan_amount', '$single', true);


                $years = get_post_meta(get_the_ID(), 'mm_s_years', '$single', true);
                $years_max = get_post_meta(get_the_ID(), 'maximum_years', '$single', true);

                //$condition = 'Minimum '.number_format($loan_amount).' BDT to Maximum '. $loan_amount_max.' BDT';
                $condition = number_format($loan_amount) . ' BDT to ' . number_format($loan_amount_max) . ' BDT';

                $year_range = $years . ' to ' . $years_max;


                $default_attr = array(
                    'alt' => $company_name,
                );
                $id = get_the_ID();
                $desc = get_the_content();
                $content_array = array(
                    'title' => $company_name,
                    'Description' => $desc,
                    'id' => $id
                );
                $modal_array[] = $content_array;

                $mm_count--;
                if ($mm_count == 0) {
                    $mm_page_no++;
                    $mm_count = 2;
                    $pagination.='<li><a href="#">' . $pagination_no++ . '</a></li>';
                }
                ?>
                <tr class="<?php echo 'info-' . $mm_page_no ?>">
                    <td><?php the_post_thumbnail('bank-logo', $default_attr); ?></td>
                    <td><?php echo $condition; ?></td>
                    <td><?php echo $year_range; ?></td>
                    <td><?php echo $cat_meta; ?></td>
                    <td><?php echo $emi; ?></td>
                    <td><?php echo $total_amount_payable; ?></td>
                <td><?php echo $interest_rate; ?></td>
                        <td>
                        <a class="btn-more" data-toggle="modal" data-target="#myModal-<?php echo $id ?>" href="#">More</a>
                        <br /><h6><?php echo edit_post_link('Edit') ?></h6>
                    </td>                            
                </tr>




            <?php endwhile; ?>

            <?php $pagination.='<li><a href="#">»</a></li></ul>'; ?>


    <?php wp_reset_query() ?>

        </tbody>
    </table>       
    <?php // echo $pagination  ?>
    <?php //echo $mm_page_nonation  ?>


    <!--Information table END-->     

    <?php if ($modal_array != NULL) { ?>
        <?php foreach ($modal_array as $modal) { ?>

            <!--modal div start-->
            <div class="modal fade" id="myModal-<?php echo $modal['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel"><?php echo $modal['title'] ?></h4>
                        </div>
                        <div class="modal-body">
                            <p><?php echo $modal['Description'] ?></p></div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                    </div>
                </div>
            </div>  <!--modal div End-->

                <?php } ?>

    <?php
    } else {
        ?>
        <div class="col-xs-12">
            <p class="m-alert">Sorry, no results found. Please try something different</p>
        </div>
    <?php } ?>



    <?php
    die();
    }

    add_action('wp_ajax_get_data', mm_get_all_informations);
    add_action('wp_ajax_nopriv_get_data', mm_get_all_informations);
?>    

1 Answer 1

3

These two lines are wrong:

add_action('wp_ajax_get_data', mm_get_all_informations);
add_action('wp_ajax_nopriv_get_data', mm_get_all_informations);

You need to quote the function name:

add_action('wp_ajax_get_data', 'mm_get_all_informations');
add_action('wp_ajax_nopriv_get_data', 'mm_get_all_informations');

If you had debugging enabled, as you should when you are working, you would have spotted the problem immediately.

1
  • Thanks for your answer, you are right. I figured it out later .... Commented Apr 28, 2014 at 6:00

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.