Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

my event-item.php

<?php
/**
 * The event template
 */ 
?>

<li>
    <article id="event-<?php the_ID(); ?>" <?php echo event_canceled($post) ? post_class('wrapper canceled') : post_class('wrapper'); ?>>

This leads to this …

<article id="event-168" class="post-168 type-wr_event status-publish hentry wrapper wr_event schoenebuecher">

However when loading this event-item.php template via ajax the custom-post-type class of wr_event is not added.

Anyone an idea why that could happen or what could lead to it?

Update:

Ajax:

$.get(
    ajax.url, 
    {
        'action': 'get_event_list',
        'order' : 'DSC',
    }, 
    function( response, status ) {
        $('ul.event-items').append(response);
        }
);

functions.php

add_action('wp_enqueue_scripts', 'theme_name_scripts');

function theme_name_scripts() {

    wp_enqueue_script( 'script-name', get_bloginfo('stylesheet_directory') . '/js/min.js', array(), '1.0.0', false );
    wp_localize_script( 'script-name', 'ajax', array( 'url' => admin_url( 'admin-ajax.php' ) ) );
}

add_action('wp_ajax_get_event_list', 'get_event_list');
add_action('wp_ajax_nopriv_get_event_list', 'get_event_list');

function get_event_list( $latest = true, $order = 'ASC', $return = false, $year = NULL, $cat = '' ) {

Now I got rid of my tag that embeds my script in the header.php file. The admin-ajax and the embeded script works however doesn't change anything at the behaviour, still no wr_event in the post-class.

share|improve this question
    
How are you loading the template? Could you add your code? –  Manolo Jan 15 at 13:10
    
Updated my question with ajax and function call. –  mathiregister Jan 15 at 13:16

1 Answer 1

up vote 1 down vote accepted

You have to use this format:

FUNCTIONS.PHP

function theme_name_scripts() {

    wp_enqueue_script( 'script-name', get_bloginfo('stylesheet_directory') . '/js/min.js', array(), '1.0.0', true );
    wp_localize_script( 'script-name', 'ajax', array( 'url' => admin_url( 'admin-ajax.php' ) ) );
}

function ajax_callback() {
     get_event_list();
}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
add_action('wp_ajax_ajax', 'ajax_callback');
add_action('wp_ajax_nopriv_ajax', 'ajax_callback');

AJAX:

$.get(
    ajax.url, 
    {
        'action': 'ajax',
        'order' : 'DSC',
    }, 
    function( response, status ) {
        $('ul.event-items').append(response);
        }
);

You may use this line to explicitly include the wr_event class:

 <article id="event-<?php the_ID(); ?>" <?php echo event_canceled($post) ? post_class('wrapper canceled wr_event') : post_class('wrapper wr_event'); ?>>

and also add die(); at the end of the template file to avoid the zero displayed.

share|improve this answer
    
Can you elobrate on that? I updated my question and now use wp_enqueue_script and wp_localize_script, doesn't change anything. –  mathiregister Jan 15 at 14:27
    
Try now. I've updated my answer. –  Manolo Jan 15 at 14:59
    
Thank you, however still no luck. I have everything exactly like you suggested and the ajax-reload still works. However still no luck with the post-class. –  mathiregister Jan 15 at 16:36
    
But I don't know why all other classes work. It's just the class of the custom-post-type that is missing. There is even the class type-wr_event but not the wr_event? –  mathiregister Jan 15 at 16:37
    
You may explicitly include that class. Look at the updated answer. –  Manolo Jan 15 at 16:52

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.