Forum Replies Created

Viewing 13 replies - 1 through 13 (of 13 total)
  • found the solution

    • This reply was modified 4 years, 9 months ago by devtotte.
    • This reply was modified 4 years, 9 months ago by devtotte.

    I successfully got the other images excluded from the all images query but if there is a empty folder and filter those images, it return all images uploaded to wp because the
    'post__in' => $wpdb->get_col("SELECT attachment_id FROM " . $wpdb->prefix . "fbv_attachment_folder WHERE folder_id = $all_folders_ids")
    argument is then empty and the deafault setting in wp is that the query returns all of that type, in this case ‘attachment’.

    Havent found a way to fix this yet.

    Yes, that worked, but maybe its better to have the notice or try to find away to do the wpdb->prepare request properly.

    I just noticed that the filter function returns all images uploaded to wordpress when getting all images. How can i exclude all images that are not added to a folder? I have this in my arguments and folder_id should be all folders. I tried this but it still return all images uploaded to wp.
    'post__in' => $wpdb->get_col("SELECT attachment_id FROM " . $wpdb->prefix . "fbv_attachment_folder WHERE folder_id = 1" OR "2" OR "3" OR "4" OR "5")
    Also tried this but since $all_folders_ids is an array it didnt work.

    
    $query = "SELECT attachment_id FROM {$wpdb->prefix}fbv_attachment_folder";
    $all_folders_ids = $wpdb->get_col($query);
    $image_args = array(
    'post_type' => 'attachment',
                'post_status' => 'inherit',
                'posts_per_page' => -1,
                'post__in' => $wpdb->get_col("SELECT attachment_id FROM " . $wpdb->prefix . "fbv_attachment_folder WHERE folder_id = $all_folders_ids")
            );

    Any suggestions on how i can exclude all other images?

    Thanks! global $wpdb; was missing and now it works.

    The WP_debug is on and prints a couple of notices:
    Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder.

    and

    Notice: Undefined offset: 0 in wp-includes/wp-db.php on line 1319

    Since they are notices they’re probably not that important and the code works now.

    Thank you!

    Ajax is sending the correct folder_id to the filtering function and i can echo the correct folder_id on the page but there is something wrong in the the query because it returns all the images and not only the images in that folder.
    So this line probably is the problem:
    'post__in' => $wpdb->get_col("SELECT attachment_id FROM " . $wpdb->prefix . "fbv_attachment_folder WHERE folder_id = $folder_id")

    That probably also is the reason tor the 500 internal server error in the js console.

    $folder_id is the folder id that ajax sends to the filtering function.

    Hi,

    Thanks for the suggestion. I tried it out and get a couple o notices and the filtering isn’t working.

    The buttons and the first query works but gives also a “Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder.” and “Notice: Undefined offset: 0 in wp-includes/wp-db.php on line 1319”. These notices appear 2 times, one for the filtering buttons and one for the image query.

    When clicking on a filtering button i get “POST localhost…wp-admin/admin-ajax.php 500 (Internal Server Error)” in js console.

    Can you help me how to send the ajax data to the filtering function?

    This was the old ajax when i was querying with a taxonomy id

    jQuery.ajax({
    			type: 'POST',
    			url: ajaxurl,
    			data: {"action": "load-filter", term: termID },

    for the category buttons:

    $taxonomy = get_terms('nt_wmc_folder');
    
         $args = array(
            'post_type' => 'attachment',
            'post_status' => 'inherit',
            'posts_per_page' => -1,
    
            );
    ?>
                <div class="row">
                    <div class="col-sm-12">
    
                    	<ul class="image-filter">
    
                            <li class="filter-btn cat-0">
                                <a href="#imagebank" onclick="cat_ajax_get(0)" class="ajax">Kaikki</a>
                            </li>
    
                            <?php foreach ($taxonomy as $tax) :
                                    $tax_id = $tax->term_id;
                                        if ($tax_id !== 1) : ?>
    
                                        <li class="filter-btn cat-<?php echo $tax->term_id ?>">
                                            <a href="#imagebank" onclick="cat_ajax_get('<?php echo $tax->term_id; ?>')" class="ajax"><?php echo $tax->name; ?></a>
                                        </li>
    
                                        <?php endif; ?>
    
                             <?php endforeach; ?>
    
                    	</ul>
    
                    </div>
                </div>

    Then just a basic query to display images:

    $image_taxonomy = 'nt_wmc_folder';
    
        $taxonomy_terms = get_terms( $image_taxonomy, array(
            'hide_empty' => 0,
            'fields' => 'ids'
        ) );
    
        $image_args = array(
                'post_type' => 'attachment',
                'post_status' => 'inherit',
                'posts_per_page' => -1,
                'orderby' => 'rand',
                'tax_query' => array(
                   array(
                       'taxonomy' => $image_taxonomy,
                       'field'    => 'id',
                       'terms'    => $taxonomy_terms
                   ),
                ),
            );
    
        ?>
    
    <div class="row">
        <div class="col-sm-12">
    
            <ul class="masonry image-list" id="imagebank">
    
            <?php
    
                $all_images = new WP_Query($image_args);
    
                    if ( $all_images->have_posts() ) : while ( $all_images->have_posts() ) : $all_images->the_post();
                        ?>
    
                    <li class="image-item">

    The filtering function (uses ajax also):

    function prefix_load_cat_images() {
    
        $tax_id = $_POST[ 'term' ];
        $taxonomy_terms = get_terms( $image_taxonomy, array(
            'hide_empty' => 0,
            'fields' => 'ids'
        ) );
            if ($tax_id != 0) {
                $image_args = array(
                        'post_type' => 'attachment',
                        'post_mime_type' =>'image',
                        'post_status' => 'inherit',
                        'posts_per_page' => -1,
                        // 'category__not_in' => array( 1 ),
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'nt_wmc_folder',
                                'field'    => 'id',
                                'terms'    => $tax_id,
                                'operator' => 'IN'
                            )
                        )
                );
            } else {
                $image_args = array(
                        'post_type' => 'attachment',
                        'post_status' => 'inherit',
                        'posts_per_page' => -1,
                        'tax_query' => array(
                           array(
                               'taxonomy' => 'nt_wmc_folder',
                               'field'    => 'id',
                               'terms'    => $taxonomy_terms
                           ),
                        ),
                    );
            }

    cant put the whole code here. its too long.

    Hi,

    Thanks for the answer.

    That did not help me solving the problem.

    I need to query all the images and display them. Then i have a button for each category (used the taxonomies until now) to filter images based on which category they belong to. Is this possible after the update?

    Hi,

    I have a similar problem. I have created a gallery with a filtering system but now it gives me an error when trying to get the terms: object(WP_Error)#1865 (2) { [“errors”]=> array(1) { [“invalid_taxonomy”]=> array(1)

    Has the taxonomy name changed (if so, to what?) or do i need to build this system in another way from scratch?

    Thanks!

    Thread Starter devtotte

    (@devtotte)

    Thanks for the reply Joy. Im aware of that plugin but im trying to avoid installing more plugins.

    This update broke my feed to. I have a endless looping feed done with marquee.js. Now the marquee code does not work at all and the custom css that i had broke.

    What is the “wprss_ajax” div doing? That seems to be the cause to my problems

    devtotte

    (@devtotte)

    @rfmcomposer
    how do you remove the cookies if the visitor decides to revoke the consent? i think you have to disable google analytics, even if it is anonymized, if the user revokes the cookie consent. do you have a solution for this?

    or do @milmor have any suggestions. the [cookie-control] shortcode removes only the ‘eucookielaw’ cookie.

    devtotte

    (@devtotte)

    take a look at what @rfmcomposer is doing.

    https://ww.wp.xz.cn/support/topic/new-cookie-law-requirement-yes-no-selection/

    https://ww.wp.xz.cn/support/topic/auto-block-doesnt-work-fix/

    Also if you check the “Auto block” checkbox all scripts should be blocked on page load.

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