Forum Replies Created

Viewing 15 replies - 1 through 15 (of 41 total)
  • Thread Starter Raza Khadim

    (@razakhadim)

    Nothing works, neither the title, nor alt or rename. When the images are in media library it works however, when I switch to full cloud migration, it doesn’t. I assume it is because the files are on the cloud?

    Here is my code for reference;

    function rename_images_on_acf_save($post_id) {

    if (get_post_type($post_id) !== 'listing') {
    return;
    }

    // Check the 'admin_rename_listing_images' ACF field
    $rename_images = get_field('admin_rename_listing_images', $post_id);
    if (!$rename_images) {
    return;
    }

    // Get the post title and sanitize it
    $post_title = get_the_title($post_id);
    $sanitized_title = str_replace(' ', '_', sanitize_title($post_title));

    // Generate the prefix for the new filenames
    $prefix = 'hey_' . $sanitized_title . '_';


    // Prepare alt text for images
    $address = get_field('listing_cpt_physical_address', $post_id);
    $locality_name = get_field('admin_address_locality', $post_id);
    $city_name = $address['city'];
    $state_name = $address['state'];
    $categories = get_field('listing_cpt_categories', $post_id);

    $category_city_strings = [];
    $category_location_strings = [];

    if (!empty($categories)) {
    foreach ($categories as $category_id) {
    // Get the term by ID
    $term = get_term($category_id);

    if (!is_wp_error($term)) {

    // Add locality if it exists and is unique
    if ($locality_name && $locality_name != $city_name) {
    $category_location_strings[] = $term->name . ' ' . $locality_name;
    }

    // Add city if it exists and is unique
    if ($city_name && $city_name != $state_name) {
    $category_location_strings[] = $term->name . ' ' . $city_name;
    }

    // Add state if it exists
    if ($state_name) {
    $category_location_strings[] = $term->name . ' ' . $state_name;
    }

    // $category_city_strings[] = $term->name . ' ' . $city_name;
    }
    }
    }

    // Combine the results into a single string
    $alt_texts = implode(", ", $category_location_strings);



    $logo = get_field('listing_cpt_logo', $post_id);
    $logo_id = $logo['ID'];
    $featured_image = get_field('listing_cpt_featured_image', $post_id);
    $featured_image_id = $featured_image['ID'];
    $gallery = get_field('listing_cpt_gallery', $post_id);


    rename_image($logo_id, $prefix, $post_title, $alt_texts);
    rename_image($featured_image_id, $prefix, $post_title, $alt_texts);

    if(!empty($gallery)) {
    foreach ($gallery as $image) {
    $image_id = $image['ID'];
    rename_image($image_id, $prefix, $post_title, $alt_texts);
    }
    }


    // Set the 'listing_rename_images' field to false after processing
    update_field('admin_rename_listing_images', false, $post_id);
    }
    add_action('acf/save_post', 'rename_images_on_acf_save', 30);

    function rename_image($image_id, $new_name_prefix, $post_title, $alt_texts) {
    // Get attachment path
    $file_path = get_attached_file($image_id);
    $unique_suffix = time() . '_' . wp_rand(100, 9999);
    // Get the original file extension
    $file_extension = pathinfo($file_path, PATHINFO_EXTENSION);
    $new_filename = $new_name_prefix . $unique_suffix . '.' . $file_extension;

    // Extract directory and file extension
    $upload_dir = wp_upload_dir();
    $new_file_path = $upload_dir['path'] . '/' . $new_filename;

    // Rename the file on the filesystem
    if (rename($file_path, $new_file_path)) {
    // Update the attachment metadata
    update_attached_file($image_id, $new_file_path);

    // Update the attachment's metadata (URLs, file paths, etc.)
    $metadata = wp_generate_attachment_metadata($image_id, $new_file_path);
    wp_update_attachment_metadata($image_id, $metadata);

    // Update the file name in the attachment post title and guid
    $attachment_data = [
    'ID' => $image_id,
    'post_title' => sanitize_text_field($post_title),
    'guid' => $upload_dir['url'] . '/' . $new_filename,
    ];
    wp_update_post($attachment_data);

    $alt_text = sanitize_text_field($alt_texts); // Use post title as alt text
    update_post_meta($image_id, '_wp_attachment_image_alt', $alt_text);
    }
    }
    • This reply was modified 1 year, 5 months ago by Raza Khadim.
    Plugin Author Raza Khadim

    (@razakhadim)

    It suggest the addresses from Google Maps, if Google Maps doesn’t have the apartment number then this plugin will not show the apartment number. Check the address by opening Google Maps and see if it returns the apartment number.

    Plugin Author Raza Khadim

    (@razakhadim)

    @justt2552 the error about Google Maps API shouldn’t impact the functionality.

    However, regarding the issue you are seeing, I will need to see the website (plugin activated) to see what could be causing it. If you can’t share the website link then another common issue is adding the right field ID.

    Note that if forms are duplicated then Elementor will carry on the same field IDs in the duplicated form. As a requirement and general good practice is to have a unique ID for elements.

    If you are copying the Field IDs from the Form widget in Elementor then it will not work because Elementor adds a prefix usually “form-field” before the ID when the page is published. Thus, you have to open the page right-click on the field you want the address auto-complete on and then get the ID from there. See this for help: https://saa.khadim.nz/kb/how-to-find-the-field-id

    Also, if you have duplicate field IDs it will not. Again, field IDs must be unique.

    I have not tested the plugin with Elementor Popups yet. I will test and get back to you on this.

    I hope this helps, let me know if there’s something else.

    Thanks

    Thread Starter Raza Khadim

    (@razakhadim)

    @staatic thank you. Looking forward to the updates.

    Plugin Author Raza Khadim

    (@razakhadim)

    The address you provided is returning Netherlands not Germany. If you want to select multiple countries use CTRL + Click (on Mac use CMD + Click). See this for help: https://saa.khadim.nz/kb/how-to-limit-search-to-one-country

    If you want to use the Restriction Type then you must enter Coordinates of the areas you want to search to be biased or restricted to. See this for help: https://saa.khadim.nz/kb/how-to-get-coordinates

    Plugin Author Raza Khadim

    (@razakhadim)

    @olahferenc27 mate, you are doing it wrong. Every single entry (except for the homepage) you have entered in the URLs is WRONG.

    All you need to do is enter the ones I have provided above and DO NOT add them in 1, add them separately.

    Your list should look like this.

    https://pasteboard.co/upObYjXcKUav.png

    Plugin Author Raza Khadim

    (@razakhadim)

    You are getting the following error:

    The current URL loading the Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key in the Cloud Console.

    I don’t think you have added the URLs to the list. Follow the following instructions and add the following URLs to the Referrer list under Website Restrictions.

    newtransfer.hu
    newtransfer.hu/*
    *.newtransfer.hu
    *.newtransfer.hu/*

    Follow these instructions: https://saa.khadim.nz/kb/how-to-get-google-maps-api-key#optional-settings

    Plugin Author Raza Khadim

    (@razakhadim)

    @olahferenc27

    This API key is not authorized to use this service or API. Please check the API restrictions settings of your API key in the Google Cloud Console to ensure that all of the APIs and services you need to use are correctly specified in the list of enabled APIs.

    Plugin Author Raza Khadim

    (@razakhadim)

    @olahferenc27 the plugin is working fine, however, your APIs are not enabled properly. Make sure you enable Maps Javascript API and Places API.

    See this for help: https://saa.khadim.nz/kb/how-to-get-google-maps-api-key

    Plugin Author Raza Khadim

    (@razakhadim)

    @olahferenc27 you must assign an ID to contact form 7 fields. CF7 doesn’t automatically assign an ID so you have to do it manually. See this: https://saa.khadim.nz/kb/how-to-add-address-autocomplete-to-contact-form-7

    Plugin Author Raza Khadim

    (@razakhadim)

    @sterndata mate, I was trying to help not trigger your paranoia. But thanks, I will keep that in mind.

    @sokar87 can you please send the link to the page where you have activated the plugin and maybe a screenshot of the settings page. I will see what I can do from that.

    Plugin Author Raza Khadim

    (@razakhadim)

    @digitalimages, it does display the town/city. For instance, search for “Wanaka, New Zealand” only instead of a full street address. However, you will not be able to ONLY show the city at the moment and disable the street address search. A good suggestion though will look into it to add in future updates.

    thanks

    Thread Starter Raza Khadim

    (@razakhadim)

    Thanks for getting back to me Michael. Seems like I could get rid of half of the data pushed to Algolia with each post. So the plugin indexes the ‘taxonomies’ which is what I need, in the Algolia dashboard I see there is another attribute ‘taxonomies_hierarchical’ which doubles up the size and the same taxonomies show up.

    https://postimg.cc/nC1svgTT

    and

    https://postimg.cc/crWgt07r

    would I be able to get rid of ‘taxonomies_hierarchical’? If yes, could you please provide some help on how to do it?

    Thanks

    • This reply was modified 2 years, 10 months ago by Raza Khadim.
    Plugin Author Raza Khadim

    (@razakhadim)

    @mariobeach hope this was resolved. I am going to close it for now but if there are any issues let me know. Thanks

    Plugin Author Raza Khadim

    (@razakhadim)

    @groggy72 glad that it is sorted now. Please do let me know if there is anything else.

Viewing 15 replies - 1 through 15 (of 41 total)