2012-09-03 2 views
0

ACF 및 AJAX에 문제가 있습니다.로드 할 때 사용자 지정 필드가 AJAX 포트폴리오에 호출되지 않습니다.AJAX/jQuery를 사용하여 고급 사용자 지정 필드 호출

나는 비교적 AJAX & PHP를 처음 사용하고 있으며이를 수정하는 방법을 잘 모르겠습니다.

add_action("wp_ajax_eq_get_ajax_project", "eq_get_ajax_project"); 
add_action("wp_ajax_nopriv_eq_get_ajax_project", "eq_get_ajax_project"); 

function eq_get_ajax_project() { 

if (!wp_verify_nonce($_REQUEST['nonce'], "portfolio_item_nonce")) { 
    exit("No naughty business please"); 
}  

$grid_classes = 'grid_9 alpha'; 
$quality = 90; 
$desired_width = 700; 
$desired_height = 500; 
$current_post_id = $_REQUEST['post_id']; 
$video_embed_code = get_post_meta($_REQUEST['post_id'], 'portfolio-video-embed', true); 
$portfolio_images = eq_get_the_portfolio_images($_REQUEST['post_id']); 
$terms = get_the_terms($_REQUEST['post_id'] , 'portfolio_categories', 'string'); 
$content_post = get_post($_REQUEST['post_id']); 
$content = $content_post->post_content; 
$content = apply_filters('the_content', $content); 
$content = str_replace(']]>', ']]>', $content); 
$post = get_post($current_post_id); 
$client = get_post_meta($current_post_id, 'oy-client', true); 
$project_url = get_post_meta($current_post_id, 'oy-item-url', true); 

ob_start(); 
?> 

이 내 jQuery를 파일입니다

jQuery(document).ready(function($) { 

/*-----------------------------------------------------------------------------------*/ 
/* Ajax Call 
/*-----------------------------------------------------------------------------------*/ 

current_post_id = ''; 
var $projectWrapper = $("#project-wrapper"); 

eQgetProjectViaAjax = function(e) { 

var post_id = $(this).attr("data-post_id"); 
current_post_id = post_id; 
var nonce = $(this).attr("data-nonce"); 
var $prev = $('.project-link[data-post_id="' + post_id + '"]').parent().parent().prev('.portfolio-item'); 
var $next = $('.project-link[data-post_id="' + post_id + '"]').parent().parent().next('.portfolio-item'); 
var prev_item_id = ''; 
var next_item_id = ''; 

// Get the id's of previous and next projects 
if ($prev.length !== 0 && $next.length !== 0) { 
    prev_item_id = $prev.find('.project-link').attr("data-post_id"); 
    next_item_id = $next.find('.project-link').attr("data-post_id"); 
} else if ($prev.length !== 0) { 
    prev_item_id = $prev.find('.project-link').attr("data-post_id"); 
} else if ($next.length !== 0) { 
    next_item_id = $next.find('.project-link').attr("data-post_id"); 
} 

$(".single-img-loader").css('opacity', 1);  
eQcloseProject(); 

$.ajax({ 
    type : "post", 
    context: this, 
    dataType : "json", 
    url : headJS.ajaxurl, 
    data : {action: "eq_get_ajax_project", post_id : post_id, nonce: nonce, prev_post_id : prev_item_id, next_post_id : next_item_id}, 
    beforeSend: function() { 
     // Activate the overlay over the current project 
     $('.project-link[data-post_id="' + post_id + '"]').next('.blocked-project-overlay').addClass('overlay-active'); 

     if(!$.browser.opera) { 
      $.scrollTo(0, 500, { easing: 'easeOutCubic' }); 
     } else { 
      $.scrollTo(0, 300, { easing: 'easeOutCubic' }); 
     } 
    }, 
    success: function(response) { 
    $projectWrapper.html(response['html']); 
    $projectWrapper.find('#portfolio-item-meta, #single-item').css('opacity', 0); 

    $("#single-item .single-img").load(function() { 
     $(this).stop().animate({ opacity: 1 }, 300); 
     $(".single-img-loader").stop().animate({ opacity: 0 }, 300); 
    }); 
}, 
complete: function() { 
    eQopenProject(); 
    $(".prev-portfolio-post, .next-portfolio-post").click(eQgetProjectViaAjax); 
    $('.prev-portfolio-post, .next-portfolio-post').click(showLoaderImg); 
    $(".close-current-post").click(eQcloseProject);    
    $('#overlay').fadeOut(500); 
    $projectWrapper.find('#portfolio-item-meta, #single-item').stop().animate({ opacity: 1 }, 400); 
} 
}); 

는 내가 어떻게 든 AJAX/jQuery를에 ACF를 등록해야하지만 난 그것을 달성 할 수있는 방법을 찾을 수 있다고 생각하고, 내가 검색 한 시간.

<?php get_field('project_name'); ?> 

이것은 전화 할 필드입니다. 당신이 AJAX 호출 (당신의 jQuery를 파일에 headJS.ajaxurl의 값)를 처리 할 수 ​​/wp-load.php을 사용하고 있다고 가정

답변

0

은 (ACF 포함) 모든 플러그인이로드되며, 사용자 정의 필드는 추가 기능을 당신의 functions.php에 게다가. get_field() 메서드를 게시 할 때 루프의 페이지에서 현재 $post->ID으로 가정하지만 원하는 경우 두 번째 인수로 다른 게시물 ID를 전달하여이를 무시할 수 있습니다. 당신의 예에서, 당신의 PHP 파일에서 읽어야 http://www.advancedcustomfields.com/docs/functions/get_field/

:

$project_name = get_field('project_name', $current_post_id); 

당신은 여기에 문서에서 자세한 내용을보실 수 있습니다

관련 문제