Support » Plugin: FileBird - WordPress Media Library Folders & File Manager » filebird taxonomies cant be found

  • Resolved theorygeorgiou

    (@theorygeorgiou)


    I created a plugin using the filebird taxonomies to display files in certain folders all of a sudden it doesn’t work, wordpress cannot find the taxonomies used by filebird anymore. All that work down the drain I imagine because you guys changed the way filebird works and don’t seem to have any documentation for it.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Support Bruce

    (@ninjateamwp)

    Hi @theorygeorgiou ,

    Thanks for using FileBird and sorry about this issue, I think you need to use FileBird’s API function? Please see the document here:

    https://ninjateam.gitbook.io/filebird/api

    If that does not help, then give me all the information about that taxonomy function you are using and what has been affected by FileBird’s changes, then we will help you further.

    In the meantime, I hope you could please remove the 1 star rating now so that we can focus on the matter in this thread?

    Thank you.

    Kind regards,
    -Bruce-

    Thread Starter theorygeorgiou

    (@theorygeorgiou)

    I prefer not spending hours rewriting a plugin I just wrote because you changed the way your plugin works entirely. I just installed a competitor plugin and it only took a few minutes to work with my plugin as where hours of troubleshooting your plugin could not. I think my experience with file bird is worth the 1 star review.

    Plugin Author Ninja Team

    (@ninjateam)

    Hello @theorygeorgiou ,

    We changed the technology to make FileBird performance better. Is this reason worth accepting please?
    For the taxonomies, FileBird lastest version does support that. If you need our help, you could just explain how you use the taxonomies and we will guide you further.

    I hope you could understand and change your rating.
    Thank you so much.

    Best regards,
    Kelly

    devtotte

    (@devtotte)

    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!

    Plugin Author Ninja Team

    (@ninjateam)

    Hi @devtotte ,

    Our latest FileBird version does not use taxonomy anymore.
    You can change into this instead
    https://wordpress.org/support/topic/query-folder-not-working-anymore/

    Let me know if this helps.

    Best regards,
    Kelly

    • This reply was modified 2 years ago by Ninja Team.
    devtotte

    (@devtotte)

    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?

    Plugin Author Ninja Team

    (@ninjateam)

    Hi @devtotte ,

    Could you provide some screenshots and sample code so we can help you further?

    Kelly

    devtotte

    (@devtotte)

    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.

    Plugin Author Ninja Team

    (@ninjateam)

    Hello,

    Please try with these code:

    For the category buttons:

     global $wpdb;
        $query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}fbv");
        $folders = $wpdb->get_results($query);
    ?>
        <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 ($folders as $folder) :
                        $folder_id = $folder->id;
                        if ($folder_id !== 1) : ?>
                            <li class="filter-btn cat-<?php echo $folder->id ?>">
                                <a href="#imagebank" onclick="cat_ajax_get('<?php echo $folder->id; ?>')" class="ajax"><?php echo $folder->name; ?></a>
                            </li>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
    <?php

    Query to display images:

    $query = $wpdb->prepare("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,
            'orderby' => 'rand',
            'post__in' => $all_folders_ids
        );
    $all_images = new \WP_Query($image_args);

    Ajax query by folder id: (filtering)

    `$image_args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_mime_type’ =>’image’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => -1,
    ‘post__in’ => $wpdb->get_col(“SELECT attachment_id FROM ” . $wpdb->prefix . “fbv_attachment_folder WHERE folder_id = your_folder_id”)
    ]);
    );`

    Let me know if this helps.

    Kelly

    • This reply was modified 2 years ago by Ninja Team.
    • This reply was modified 2 years ago by Ninja Team.
    • This reply was modified 2 years ago by Ninja Team.
    devtotte

    (@devtotte)

    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 },
    devtotte

    (@devtotte)

    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.

    Plugin Author Ninja Team

    (@ninjateam)

    global $wpdb;
            $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 = (int)$folder_id")
            );
            $all_images = new \WP_Query($image_args);
            // var_dump(($all_images));

    Please try the code above, did the result of ($all_images->posts) give you all the posts in folder you want? You can turn WP_Debug to get the error information from error 500.

    Let us know the update please.

    devtotte

    (@devtotte)

    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!

    Plugin Author Ninja Team

    (@ninjateam)

    Hi @devtotte ,

    To remove the notice, you can replace this code

    ‘$query = $wpdb->prepare(“SELECT * FROM {$wpdb->prefix}fbv”);
    $folders = $wpdb->get_results($query);’

    by this

     $query = "SELECT * FROM {$wpdb->prefix}fbv";
        $folders = $wpdb->get_results($query);

    Let me know if this helps.

    Kelly

    devtotte

    (@devtotte)

    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?

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘filebird taxonomies cant be found’ is closed to new replies.