函数中的函数错误。php?

时间:2014-04-27 作者:rafsuntaskin

我在自定义主题中使用以下函数通过AJAX加载帖子。但由于某种原因,当我将主题上传到一个实时服务器时,它打破了WP管理小部件的拖放,并显示了死亡的白色屏幕。

我不知道我做错了什么。我的屁股上没有空格。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 个回复
最合适的回答,由SO网友:s_ha_dum 整理而成

这两行是错误的:

add_action(\'wp_ajax_get_data\', mm_get_all_informations);
add_action(\'wp_ajax_nopriv_get_data\', mm_get_all_informations);
您需要引用函数名:

add_action(\'wp_ajax_get_data\', \'mm_get_all_informations\');
add_action(\'wp_ajax_nopriv_get_data\', \'mm_get_all_informations\');
如果你有debugging enabled, 正如您在工作时应该做的那样,您会立即发现问题。

结束