Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter pczk

    (@podlasiaczek)

    Hi,

    I sent from email pod..cz..@gm…com

    Thank You for Your help.

    Thread Starter pczk

    (@podlasiaczek)

    Please give private contact to You. (@) I will send.

    Thread Starter pczk

    (@podlasiaczek)

    Thank You very much. (RavanH) It works.

    Thread Starter pczk

    (@podlasiaczek)

    Thank you for your answer. Unfortunately it does not work. Maybe I’m doing something wrong?

    custom.js

    (function($){
        'use strict';
    
        $(function (e) {
    
            $('.get_project').on( 'click', function(e) {
                e.preventDefault();
                var postid = $(this).attr('data-postid');
                console.log(postid);
    
    			$('.TARGETDIV').html('<img src="/wp-content/themes/rt_gantry_wp/images/Loader.gif" height="150" width="150" />');
                $.ajax({
                    type: "POST",
                    url: my_ajax_object.ajax_url,
                    data: {
                        action: 'my_load_ajax_content',
                        postid: postid,
                    }
                }).done(function (data) {
                    $('.TARGETDIV').html(data);
                    $(document).trigger('post-load');		
                });
            });
        });
    })(jQuery);

    functions.php

    function my_load_ajax_content () {
    
        $pid = intval($_POST['postid']);
        $the_query  = new WP_Query(array('p' => $pid));
    
        if ($the_query->have_posts() && $pid > 0) {
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                $data = '
                <div class="post-container">
                    <div id="project-content">
                        <h1 class="entry-title">' . get_the_title() . '</h1>
                        <!-- <div class="entry-content">'. get_the_content() . '</div> -->
    					<div class="entry-content">' . do_shortcode(get_post_field('post_content', $pid)). '</div>
                    </div>
                </div>  
                ';
            }
        }
        else {
    
            $data = '<div id="postdata">'.__('Nothing found', THEME_NAME).'</div>';
        }
        wp_reset_postdata();
    
        echo '<div id="postdata">'. $data .'</div>';
        die();
    }
    
    add_action ( 'wp_ajax_nopriv_my_load_ajax_content', 'my_load_ajax_content' );
    add_action ( 'wp_ajax_my_load_ajax_content', 'my_load_ajax_content' );
    
    function my_enqueue() {
        wp_register_script( 'ajax-script', get_template_directory_uri() . '/js/custom.js', array('jquery') );
        wp_localize_script( 'ajax-script', 'my_ajax_object',
            array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
        );
    	
        wp_enqueue_script( 'ajax-script' );
    	
    	
    }
    
    add_action( 'wp_enqueue_scripts', 'my_enqueue' );
Viewing 4 replies - 1 through 4 (of 4 total)