WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to dynamically retrieve the post thumbnail in a modal pop-up using custom prev/next navigation. I need to retrieve the next and previous Post ID based on whatever Post is currently showing.

Even though I supply the current post ID, my function produces the following error:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Custom_Work_Portfolio' does not have a method 'adjacent_post_where' in /Users/tak/Sites/lauraterry/wp-includes/plugin.php on line 173 
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Custom_Work_Portfolio' does not have a method 'adjacent_post_sort' in /Users/tak/Sites/lauraterry/wp-includes/plugin.php on line 173

The relevant sections of code are below:

        // Uses get_previous_post to retrieve post ID see:
         * Function to call the content loaded for logged-in and anonymous users
        public function load_ajax_content ( $post_id ) {
            $post_id = $_POST[ 'post_id' ];

            global $post;
            $post = get_post($post_id);
            $next_post = get_next_post(true, '1');
            $prev_post = get_previous_post(true, '1');

            if (has_post_thumbnail($post_id)) {
                $sketch_id = get_post_thumbnail_id($post_id);  
                $attachment = get_post( $sketch_id );
                $caption = $attachment->post_excerpt;
                $response = '<figure>'. get_the_post_thumbnail($post_id, 'large-sketch') .'<figcaption><p>'. $caption .'</p></figcaption></figure><nav><ul><li class="prev"><a href="#" class="button radius previous-sketch secondary" data-id="'. $next_post->ID .'">Previous</a></li>
            <li class="next"><a href="#" class="button radius next-sketch secondary" data-id="'.  $prev_post->ID  .'">Next</a></li></ul></nav>';
                echo $response;


public function __construct() {
        add_action( 'wp_ajax_load-content', array($this, 'load_ajax_content' ));
        add_action( 'wp_ajax_nopriv_load-content', array($this, 'load_ajax_content' ));


 (function($) {

$.fn.displayPost = function() {


    var post_id = $(this).data("id");
    var id = "#" + post_id;

    // Check if the reveal modal for the specific post id doesn't already exist by checking for it's length
    if($(id).length == 0 ) {
        // We'll add an ID to the new reveal modal; we'll use that same ID to check if it exists in the future.
        var modal = $('<div>').attr('id', post_id ).addClass('reveal-modal').appendTo('body');
        var ajaxURL = MyAjax.ajaxurl;
            type: 'POST',
            url: ajaxURL,
            data: {"action": "load-content", post_id: post_id },
            success: function(response) {
                modal.empty().html(response).append('<a class="close-reveal-modal">&#215;</a>').foundation('reveal', 'open');
                modal.bind('opened', function() {
                    // Reset visibility to hidden and set display: none on closed reveal-modal divs, for some reason not working by default when reveal close is triggered on .secondary links  
                    $(".reveal-modal:not('.reveal-modal.open')").css({'visibility': 'hidden', 'display' : 'none'})
                    // Trigger resize 
                return false;
     //If the div with the ID already exists just open it.
     else {
         $(id).foundation('reveal', 'open');

     // Recalculate left margin on window resize to allow for absolute centering of variable width elements
         var left;
            left = Math.max($(window).width() - $(id).outerWidth(), 0) / 2;
                left:left + $(window).scrollLeft()


// Apply the function when we click on the .reveal link
   jQuery(document).on("click", ".reveal,.secondary", function() {


// Open new modals on secondary paging links in open modal window
jQuery(document).on("click", ".secondary", function() {
    var id = jQuery(this).closest("div").attr("id");
       jQuery(id).foundation('reveal', 'close');

Template excerpt:

 <ul id="sketchbook-container" class="large-block-grid-4">

        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
          'category_name' => 'sketchbook-2',
          'orderby' => 'date',
          'order' =>  'ASC',
          'posts_per_page' => 8,
          'paged'=> $paged 

          $loop = new WP_Query($args);
          while($loop->have_posts()) : $loop->the_post(); ?>


            if( has_post_thumbnail() ) :
              $sketch = get_post_thumbnail_id($post->ID);     
              $large_image = get_attachment_link( $sketch );

              <li class="sketch-leaf">
                <figure class="sketch-thumb">

                  <a href="<?php echo $large_image; ?>" data-id="<?php the_ID(); ?>"  class="reveal" >
                  <?php echo get_the_post_thumbnail($post->ID, 'medium-sketch'); ?>



            <?php endif; ?>

        <?php endwhile; ?>

share|improve this question
The error you quoted does not seem to be connected to the following code. It's seems to be coming from some filter where you are adding callback for your class, but with invalid method name. – Rarst Jun 30 '13 at 22:02
Hmm, I just added the action hooks for the class where I load load_ajax_content. The errors are definitely being produced by the inclusion of the custom next_post and previous_post functions in paging_link_nav – tnog Jun 30 '13 at 22:20
Where is the code for paging_link_nav? – s_ha_dum Jun 30 '13 at 23:15
Sorry, I updated my code above, tried to simplify it. I consolidated the code from paging_link_nav into load_ajax_content. But that didn't resolve the issue. – tnog Jun 30 '13 at 23:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.