簡體   English   中英

500個內部服務器錯誤jQuery和WordPress

[英]500 internal server error jQuery and WordPress

我正在嘗試在我的WordPress項目中使用ajax根據其帖子ID動態加載視頻。 當我單擊視頻鏈接時,出現錯誤500內部服務器錯誤。 我通過ajax將帖子ID發送到PHP腳本,在那里我嘗試使用ID獲取帖子的帖子元,然后顯示存儲在該帖子元中的視頻網址。 誰能看到我要去哪里錯了?

下面是我的簡碼功能

/**
     * Render the HTML code for the  speaker interviews
     *
     * @return $output string The HTML code to be rendered, caught by ob_start();
     */

    function test_view_shortcode_fn( $attributes ) {

        ob_start();

        $args = array( 'post_type' => 'test_video',
                                       'post_status' => 'publish',
                                       'posts_per_page' => 1
                                       );

        $main_video = new WP_Query( $args );

        if( $main_video->have_posts() ) : while ( $main_video->have_posts() ) : $main_video->the_post(); 


        $video = get_post_meta( get_the_ID(), '_video_url' );
        $poster = get_post_meta( get_the_ID(), '_video_poster' );

        ?>
            <div class="row">
                <div class="columns small-12 medium-7 large-8 video-single">
                    <?php echo do_shortcode("[video src='" . $video[0] . "' poster='" . $poster[0] . "' width='800' height='640' preload='none' ]") ?>
                    <ul class="channel-share">
                        <li><a class="text-center" href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>" title="Share on Facebook" target="_blank"><i class="fa fa-facebook"></i></a></li>
                        <li><a class="text-center" href="https://twitter.com/home?status=<?php the_title(); ?>-<?php the_permalink(); ?>" title="Share on Twitter" target="_blank"><i class="fa fa-twitter"></i></a></li>
                        <li><a class="text-center" href="https://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Share on Linked In" target="_blank"><i class="fa fa-linkedin"></i></a></li>
                        <li><a class="text-center" href="https://plus.google.com/share?url=<?php the_permalink(); ?>" title="Share on Google+" target="_blank"><i class="fa fa-google-plus"></i></a></li>
                    </ul>
                    <?php the_content(); ?>
                </div>
                <div class="columns small-12 medium-5 large-4 video-single">
                    <aside>
                        <ul class="iot-channel-sidebar">
                            <?php

                            $args = array(
                                    'post_type'      => 'test_video',
                                    'posts_per_page' => 5,
                                    'orderby'        => 'rand'
                                );

                            $channel = new WP_Query( $args );

                            if( $channel->have_posts() ) : while( $channel->have_posts() ) : $channel->the_post();
                                $poster = get_post_meta( get_the_ID(), '_video_poster' );
                                $id = get_the_ID();
                                $video_ajax_url = VIDEO_URI . '/inc/video_ajax.php';
                            ?>
                            <?php if( $poster ) { ?>
                                <li class="video-archive-item">
                                    <div class="video-poster">
                                        <a title="<?php the_title(); ?>" id="video_<?php echo $id; ?>">
                                            <img src="<?php echo $poster[0]; ?>" alt="<?php the_title(); ?>" />
                                        </a>
                                    </div>
                                    <div class="video-title">
                                        <a title="<?php the_title(); ?>">
                                            <h4><?php the_title(); ?></h4>
                                        </a>
                                    </div>
                                </li>
                                <script type="text/javascript">
                                        jQuery("#video_<?php echo $id; ?>").click(function(){
                                            jQuery.ajax({
                                                url: '<?php echo $video_ajax_url; ?>',
                                                type: 'POST',
                                                data: {id: '<?php echo $id; ?>'},
                                                    success: function(data){
                                                    $('.wp-video').html(data); // Load data into a <div> as HTML

                                                }
                                            });
                                        });
                                </script
                            <?php } ?>                  
                            <?php endwhile; endif; ?>
                        </ul>
                    </aside>
                </div>
            </div>

        <?php  endwhile; endif;

        $output = ob_get_clean();

        return $output;


    }

我的ajax:

<?php

global $post;
$postID = $_POST['id'];

setup_postdata( $postID ); 

echo $postID;

$video = get_post_meta( $postID, '_video_url' );
$poster = get_post_meta( $postID, '_video_poster' );

echo do_shortcode("[video src='" . $video[0] . "' poster='" . $poster[0] . "' width='800' height='640' preload='none' ]")



?>

我最終意識到這是由於WordPress並未加載到通過Ajax調用的PHP文件中。

為了解決這個問題,我在Ajax調用的PHP腳本的頂部包含了wp-load.php,它可以完美地工作。 這是我添加到我的PHP文件中的內容。

<?php
$filename = "../../../../wp-load.php";

include($filename);

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM