• I have updated a hook to pull in one line of post meta, but nothing is returned. Any suggestions? Here’s the code:

    add_filter('ajax_wpqsf_reoutput', 'customize_output', '', 4);
    function customize_output($results , $arg, $id, $getdata ){
    	// The Query
    	$apiclass = new ajaxwpqsfclass();
    	$query = new WP_Query( $arg );
    	ob_start();   //$results ='';
    		// The Loop
    		if ( $query->have_posts() ) {
    			while ( $query->have_posts() ) {
    				$query->the_post();
    					echo '<li>'.get_permalink().'</li>';
    					echo '<li>'.get_post_meta('33', 'course2_title', true).'</li>';
    			}
    			echo $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id);
    		} else {
    			echo 'No se han encontrado resultados.';
    		}
    		/* Restore original Post Data */
    		wp_reset_postdata();
    
            $results = ob_get_clean();
                return $results;
    }

    https://www.ads-software.com/plugins/ajax-wp-query-search-filter/

Viewing 1 replies (of 1 total)
  • Thread Starter Blake Bertuccelli-Booth

    (@elblakeo31)

    Thanks to tck30’s comment, I figured it out.

    For reference, I needed to add “$query->post->ID”.

    Working code:

    add_filter('ajax_wpqsf_reoutput', 'customize_output', '', 4);
    function customize_output($results , $arg, $id, $getdata ){
    	// The Query
    	$apiclass = new ajaxwpqsfclass();
    	$query = new WP_Query( $arg );
    	ob_start();   //$results ='';
    		// The Loop
    		if ( $query->have_posts() ) {
    			while ( $query->have_posts() ) {
    				$query->the_post();
    					echo '<li>'.get_permalink().'</li>';
    					echo '<li>'.get_post_meta( $query->post->ID, 'course2_title', true).'</li>';
    			}
    			echo $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id);
    		} else {
    			echo 'No se han encontrado resultados.';
    		}
    		/* Restore original Post Data */
    		wp_reset_postdata();
    
            $results = ob_get_clean();
                return $results;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘get_post_meta returns empty’ is closed to new replies.