Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Mark

    (@cybertech537)

    You are right, I was using new product editor(beta version).
    I unchecked this option now the custom field shows up but what else if I want to add field to new product editor(beta)?
    Thanks.

    Thread Starter Mark

    (@cybertech537)

    https://prnt.sc/lNCaeNhajkhr
    This one shows the field.

    https://prnt.sc/FEa_vahopLwD
    But this one does not.

    Thread Starter Mark

    (@cybertech537)

    page template named “property.php”

    <form id="property-filter" class="mb-10">
                <select name="property_type" id="property-type">
                    <option value="">Select Property Type</option>
                    <?php
                    $property_types = get_terms('property-type');
                    foreach ($property_types as $type) {
                        echo '<option value="' . $type->slug . '">' . $type->name . '</option>';
                    }
                    ?>
                </select>
    
                <select name="property_location" id="property-location">
                    <option value="">Select Property Location</option>
                    <?php
                    $property_locations = get_terms('property-location');
                    foreach ($property_locations as $location) {
                        echo '<option value="' . $location->slug . '">' . $location->name . '</option>';
                    }
                    ?>
                </select>
    
                <input type="text" name="search" id="property-search" placeholder="Search...">
                <input type="submit" value="Filter" class="btn btn-primary cursor-pointer">
            </form>
    
            <?php
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $property = new WP_Query(array(
                'post_type'     => 'property',
                'posts_per_page'=> 3,
                'paged' => $paged
            ));
            if( $property -> have_posts() ){
            ?>
            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6" id="property-results">
                <?php 
                while( $property -> have_posts() ){
                    $property -> the_post();
                    get_template_part( 'template-parts/property-card' );
                }
                ?>
            </div>
            <?php 
            echo '<div class="pagination-container pagination mt-10 text-center">'. paginate_links(array(
                'total' => $property->max_num_pages,
                'current' => max(1, $paged)
            )).'</div>';
            }
            wp_reset_postdata();
            ?>

    functions.php

    
    // include assets
    function wptheme_assets(){
    
        wp_enqueue_script('property-ajax', get_template_directory_uri() . '/assets/js/property-ajax.js', array('jquery'), '1.0', true);
        wp_localize_script('property-ajax', 'property_ajax_params', array(
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('property-nonce')
        ));
    
    }
    add_action( 'wp_enqueue_scripts', 'wptheme_assets' );
    
    // ajax filter
    add_action('wp_ajax_filter_properties', 'filter_properties');
    add_action('wp_ajax_nopriv_filter_properties', 'filter_properties');
    function filter_properties() {
        check_ajax_referer('property-nonce', 'nonce');
    
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
        $args = array(
            'post_type' => 'property',
            'posts_per_page' => 3,
            'paged' => $paged,
            'tax_query' => array(
                'relation' => 'AND',
            ),
        );
    
        if (isset($_GET['property_type']) && $_GET['property_type'] !== '') {
            $args['tax_query'][] = array(
                'taxonomy' => 'property-type',
                'field' => 'slug',
                'terms' => $_GET['property_type'],
            );
        }
    
        if (isset($_GET['property_location']) && $_GET['property_location'] !== '') {
            $args['tax_query'][] = array(
                'taxonomy' => 'property-location',
                'field' => 'slug',
                'terms' => $_GET['property_location'],
            );
        }
    
        if (isset($_GET['search']) && $_GET['search'] !== '') {
            $args['s'] = $_GET['search'];
        }
    
        $properties = new WP_Query($args);
    
        if ($properties->have_posts()) {
            while ($properties->have_posts()) {
                $properties->the_post();
                get_template_part( 'template-parts/property-card' );
            }
            // Pagination output
            echo '<div class="pagination">';
            echo paginate_links(array(
                'total' => $properties->max_num_pages,
                'current' => max(1, $paged),
            ));
            echo '</div>';
        } else {
            echo 'No properties found';
        }
    
        wp_reset_postdata();
        wp_die();
    }

    property-ajax.js

    jQuery(document).ready(function($) {
    
        function filterProperties(page) {
    
            var filter = $('#property-filter');
    
            var ajaxurl = property_ajax_params.ajax_url;
    
            var data = filter.serialize();
    
            if (page !== undefined) {
    
                data += '&paged=' + page;
    
            }
    
            $.ajax({
    
                url: ajaxurl,
    
                data: data + '&action=filter_properties&nonce=' + property_ajax_params.nonce,
    
                type: 'GET',
    
                beforeSend: function(xhr) {
    
                    // You can add loading indicators here
    
                },
    
                success: function(response) {
    
                    $('#property-results').html(response);
    
                    $('.pagination-container').html(''); // Clear pagination container
    
                },
    
                error: function(errorThrown) {
    
                    console.log(errorThrown);
    
                }
    
            });
    
        }
    
        $('#property-filter select').change(function(e) {
    
            e.preventDefault();
    
            filterProperties();
    
        });
    
        $('#property-filter').submit(function(e) {
    
            e.preventDefault();
    
            filterProperties();
    
        });
    
        $(document).on('click', '.pagination a', function(e) {
    
            e.preventDefault();
    
            var pageWithSlash = $(this).attr('href').split('/page/')[1];
    
            var page = pageWithSlash.split('/')[0];
    
            filterProperties(page);
    
            console.log(page);
    
        });
    
    });
    Thread Starter Mark

    (@cybertech537)

    Apologies, but I’m not looking for select options. Instead, I’m seeking a way to showcase the taxonomy list in a horizontal view. When a taxonomy item is clicked, it should filter accordingly, and I’d also like to display a “load more” button for loading posts of the next page/rest.

    https://prnt.sc/iZoaeMtUwd38

    Thread Starter Mark

    (@cybertech537)

    It works fine.
    Thanks a ton.

    Thread Starter Mark

    (@cybertech537)

    The issue is resolved.

    Thread Starter Mark

    (@cybertech537)

    Yes, It is working on console as you showed on video but doesn’t work on click event. Do you have any solution?

Viewing 7 replies - 1 through 7 (of 7 total)