Hi gnr5 (dope name and profile pic!),
this is something that is technically possible but will probably require more work than it’s worth. Up to you to decide!
HD Quiz stores images by ID
– not direct URL paths. This is so that your site can use srcset
, lazy loading, etc. What this means is that you can’t really select an image by URL path (more on this below), BUT, if you upload your images beforehand and get the IDs of each image, then we can use that instead.
PRO TIP: Ids are sequential. So if you upload 100 images and the first image has an id of 4400
, then the last image will have an id of 4500
. This way you don’t have to check each and every image. Just note that I have a feeling that the order they are “added” is irrelevant and ids are assigned based on “upload completed” – so something to pay attention to.
So if you want to go this route, what can you do? Based on your past post history, I’m going to assume that you are fairly comfortable with making small coding edits, so let’s dive in!
On ./includes/tools/csv_import.php
on line 249
you will see $fields["featured_image"]["value"] = 0;
This is where we essentially set the featured image ID to 0 – so no image. If you were to replace 0 with a value from your CSV however…
$fields["featured_image"]["value"] = intval($csvAsArray[$start][14]);
you’ve now set the featured image ID to the 15th column from your CSV!
But what if this isn’t good enough. What if you really, really want to use URLs instead of IDs. Well doing the following should be an absolute last case scenario, and I will REFUSE to offer any further support going down this path – you can take a look at ./includes/functions.php
. There is a function hdq_get_attachment_id
which attempts to get the id of an image from a URL.
So example code would look something like this.
$image_url = sanitize_text_field($csvAsArray[$start][14]);
$image_id = hdq_get_attachment_id($image_url);
$fields["featured_image"]["value"] = $image_id;