使用自定义帖子类型的Ajax获取自定义字段

时间:2018-02-21 15:34:14

标签: javascript php jquery ajax wordpress

我正在使用滑块,客户端问我什么时候有人来滑动图像它翻转,当点击它的视频节目弹出窗口时,我的代码工作,当我放入模板页面,但当我把它推入functions.php来制作短代码它停止工作。我有点混淆我的代码,因为我使用自定义帖子类型滑块和创建我创建了一个短代码。我将所有代码放在functions.php文件中以制作短代码。

// Sponsor Post Type Shortcode Function

function speakers_shortcode( $atts ) { ?>
    <section class="sp_slider slider">
        <?php
        $args = array( 'post_type' => 'speakers', 'posts_per_page' => 10 );
        $the_query = new WP_Query( $args ); 


        if ( $the_query->have_posts() ) :
            while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                <div class="slide_div">
                    <div id="flip_wrap">
                        <div class="flip_outer">
                            <div class="vid_flip">
                                <div class="ab_flpr_inner">
                                    <div class="front_flip">
                                        <div class="sp_thumb">
                                            <?php the_post_thumbnail('full'); ?>
                                        </div>
                                    </div>
                                    <div class="back_flip">
                                        <h2>Watch Video</h2>
                                    </div>
                                </div>
                            </div>
                        </div>  
                    </div>
                    <div class="slide_cntnt">
                        <h2><?php the_title(); ?></h2>
                            <a class="pop_btn rsrv_btn pink_bg white" href="<?php the_permalink(); ?>" onClick="popup('<?php echo $post->ID; ?>')">Make Reservation</a>
                        <div class="entry-content">
                            <?php //the_content(); ?> 
                        </div>
                    </div>
                </div>          
            <?php endwhile;
        endif; ?>
    </section> 

<?php
}
add_shortcode( 'speaker-shortcode', 'speakers_shortcode');

this code which i am using for ajax and as well for popup
    function popup($pageid) {
  //alert($pageid);
  jQuery.ajax({
    type: "GET",
    url: "<?php echo get_template_directory_uri(); ?>/getcontent.php",
    data: {
      'pageid' : $pageid
    },
    dataType: "text",
    success: function(response){
    document.getElementById("page_content_sec").innerHTML = response; //sending data to show on list
      jQuery("#page_content").show();

    }
  });
}
jQuery(document).ready(function(){
    jQuery('.pop_btn').click(function(event){
        jQuery('#page_content').show();
        event.preventDefault();
    });
    jQuery('#close').click(function(event){
        jQuery('#page_content').hide();
        document.getElementById("page_content_sec").innerHTML = ""; //sending data to show on list
        event.preventDefault();
    });         
});

目前我试图获得帖子的标题来检查它是否有效但我无法获得

// here is the code which i am using on get content page
<?php 
require_once("../../../wp-config.php"); 


if(isset($_GET['pageid'])) {
    $pageid = $_GET['pageid'];
} else {
    $pageid = "";
}

//echo $pageid;
$content_post = get_post($pageid);
    $content = $content_post->post_content; ?>
        <div class="pop_hd">
                <h2 style="color: #fff;"><?php echo get_the_title($pageid); ?></span></h2>
        </div>

    <?php

die;
?>

0 个答案:

没有答案