Support » Plugin: Categories Images » z_taxonomy_image_url returns only full size image

  • The backend of the plugin is working well but when I use this code:
    echo z_taxonomy_image_url(*Category ID*, 'medium');
    It only returns the ‘full’ size url version of the category image.

    As a test I also tried
    echo wp_get_attachment_image(*Image ID*, 'medium');
    and this correctly returns the ‘medium’ size of the category image.

    I tried editing the plugin code directly to force a medium image with no luck, anyone know what I’m doing wrong here?

    https://wordpress.org/plugins/categories-images/

Viewing 4 replies - 1 through 4 (of 4 total)
  • i also run into this problem an found out that the internal function “z_get_attachment_id_by_url” doesnt return any result and the full image src is the fallback in that case.

    so i modified that function with code i found here: https://frankiejarrett.com/2013/05/get-an-attachment-id-by-url-in-wordpress/

    result in /wp-content/plugins/categories-images/categories-images.php at line 170

    
    
    function z_get_attachment_id_by_url($image_src) {
      // Split the $url into two parts with the wp-content directory as the separator
      $parsed_url  = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $image_src );
      // Get the host of the current site and the host of the $url, ignoring www
      $this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
      $file_host = str_ireplace( 'www.', '', parse_url( $image_src, PHP_URL_HOST ) );
      // Return nothing if there aren't any $image_src parts or if the current host and $url host do not match
      if ( ! isset( $parsed_url[1] ) || empty( $parsed_url[1] ) || ( $this_host != $file_host ) ) {
        return NULL;
      }
      // Now we're going to quickly search the DB for any attachment GUID with a partial path match
      // Example: /uploads/2013/05/test-image.jpg
      global $wpdb;
      $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parsed_url[1] ) );
      // Returns null if no attachment is found
      $id = $attachment[0];
      return (!empty($id)) ? $id : NULL;
    }

    now it does work for me – a plugin update with that fixed wouldt be great.

    I also faced with the same problem. But later find out with plugin everything is ok.

    If you check out category-images.php you’ll find function z_get_attachment_id_by_url($image_src) which is responsible to return attachment’s ID.

    // get attachment ID by image url
    function z_get_attachment_id_by_url($image_src) {
        global $wpdb;
        $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid = %s", $image_src);
        $id = $wpdb->get_var($query);
        return (!empty($id)) ? $id : NULL;
    }

    In my case, I changed my url when I copied the site to the server (e.g. from example.dev to example.com). That is why that function returned null. After updating my wp_posts table everything worked just fine!

    I’m getting the same problem, by it retrieves me only thumbnail size.

    @bahriddin can you please tell me how you fixed it at the end?
    did you put website URL some where?

    Thanks

    I fixed my problem using MySQL’s replace function:

    Replace

    I changed example.dev to example.com. That’s all!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘z_taxonomy_image_url returns only full size image’ is closed to new replies.