Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jarvis's Achievements

Advanced Member

Advanced Member (4/5)

3

Reputation

2

Community Answers

  1. Thanks @requinix This was my solution: foreach ($blocks as $block) { if ($block['blockName'] == 'acf/testimonials') { foreach($block['attrs']['data'] as $key => $value) { if (str_starts_with($key,'testimonials_') && str_ends_with($key,'_testimonial')) { $testimoainal[] = $value . "<br>"; } } } } echo '<pre>'; print_r($testimoainal); echo '</pre>'; Perhaps not overly pretty but does the job
  2. @ginerjm unfortunately, this is how the data is stored and is beyond my control. I'm just having to work with what's already there @requinix parse_blocks returns the data as an array. From what I can tell, there is no way to limit what's returned, it just gets everything
  3. Hi, I'm hoping someone can help. I've got the following array: Array ( [blockName] => acf/testimonials [attrs] => Array ( [name] => acf/testimonials [data] => Array ( [title] => [_title] => field_6017f48066e05 [title_tag] => H1 [_title_tag] => field_6017f48d66e06 [testimonials_0_testimonial] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque id scelerisque ante. Sed nibh tortor, laoreet vitae risus a, ultricies congue ex. Nulla iaculis, libero et feugiat efficitur, lorem turpis blandit nisi, vel convallis enim ex eget eros. [_testimonials_0_testimonial] => field_6017f4631cdc0 [testimonials_0_name] => [_testimonials_0_name] => field_6017f4691cdc1 [testimonials_0_company] => [_testimonials_0_company] => field_6017f46e1cdc2 [testimonials_1_testimonial] => Maecenas fermentum fermentum nibh quis maximus. Vivamus non tellus sed odio convallis aliquet. Quisque volutpat metus vel quam facilisis ullamcorper. [_testimonials_1_testimonial] => field_6017f4631cdc0 [testimonials_1_name] => [_testimonials_1_name] => field_6017f4691cdc1 [testimonials_1_company] => [_testimonials_1_company] => field_6017f46e1cdc2 [testimonials] => 2 [_testimonials] => field_6017f44c1cdbf [add_background_colour] => 0 [_add_background_colour] => field_6017f4ad66e07 [image] => [_image] => field_6017f72f66e09 [overlay_colour] => Light [_overlay_colour] => field_6017f75066e0a [overlay_opacity] => 0 [_overlay_opacity] => field_6017f76d66e0b ) [mode] => edit ) [innerBlocks] => Array ( ) [innerHTML] => [innerContent] => Array ( ) ) This comes from the following code: $blocks = parse_blocks($post->post_content); foreach ($blocks as $block) { echo '<pre>'; print_r($block); echo '</pre>'; if ($block['blockName'] == 'acf/testimonials') { $testimoainal[] = $block['attrs']['data']['testimonials_0_testimonial']; } } echo '<pre>'; print_r($testimoainal); echo '</pre>'; What I'm trying to do, is create an array with just the testimonials. I can see how to get the first one but what I can't work out is how I could loop through to grab the others, especially as I don't know how many there might be. So can't leave it hard coded I wonder how I can achieve this please?
  4. Ah of course! Thank you, that's sorted it Very much appreciated
  5. Hi @Barand Many thanks (as usual!) for the reply. I added a field to the initial array called 'sort_date' => $date The $date format is dmY I've amended the usort function: usort($attendees, function($a, $b) { $x = $a['sort_date']<=>$b['sort_date']; if ($x == 0) return $a['course']<=>$b['course']; return $x; }); But sadly, the courses don't seem to be in the order of the sort date (which would be ascending). Instead, they just seem to be ignoring the sorting. Have I done something wrong?
  6. Good morning, I'm hoping someone can please kindly help. I have an array of data: $attendees[] = array( 'course'=> $course_title, 'date' => $course_start_date, 'name' => $order->get_billing_first_name().' '.$order->get_billing_last_name(), 'email' => $order->get_billing_email(), 'phone' => $order->get_billing_phone(), 'qty' => $result['quantity'], 'order' => $order_id_number ); I then group the data: // group data by course $result = array(); foreach ($attendees as $attendee): $result[$attendee['course']][] = $attendee; endforeach; Using a foreach loop (foreach ($result as $itemName => $rows):) I output the data. This works fine. However, the order isn't right. I'd like to sort the output by alphapetical. So I added the following before the foreach: sort($result); However, it doesn't make a jot of difference. Have I missed something really obvious as to why its not working? Thanks
  7. Hi @Barand Is that due to the `mfs_training_course_email_notifications` as opposed to SELECT * FROM mfs_training_course_email_notifications (no backticks) It's the only difference I can see? You're right! $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM `$table_name` WHERE `start_date` = %s AND `email_sent` = %d", $test, $email_sent), Worked! Thanks
  8. Hi All, Apologies if this is in the wrong place. I'm using Wordpress to run a SQL query as per the below: $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE 'start_date' = %s AND 'email_sent' = %d", $test, $email_sent), ARRAY_A); This outputs the following: SELECT * FROM mfs_training_course_email_notifications WHERE 'start_date' = '2023-06-17' AND 'email_sent' = 0 Which returns 0 results. However, if I know there is a result. If I go to PHPMyAdmin and run the following: SELECT * FROM `mfs_training_course_email_notifications` WHERE `start_date` = '2023-06-17' AND `email_sent` = 0 It works and returns a result. If I alter the code: $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE 'email_sent' = %d", $email_sent), ARRAY_A); Therefore: SELECT * FROM mfs_training_course_email_notifications WHERE 'email_sent' = 0 It returns results, so seems the issue is the start_date part. However, I'm perplexed as to why? The start_date column is a date field - in case that makes any odds!? Am trying to prevent doing the last search, then adding an IF statement to check the date. Would rather try to include both in the initial query to make things quicker/streamlined. Hope that makes sense!?
  9. Literally: $json[] = array( 'name' => $itemName, 'desc' => 'Booking #'.$row["booking_id"], 'values' => $data ); $itemName = ''; That works! Thanks, pretty obvious really
  10. Thanks @kicken Sadly, the data has to be that format as it's passed to into creating a gantt chart using a 3rd party tool (a demo can be seen here).
  11. Hi All, I've got the following code, which creates my JSON feed. It works perfectly: // group data by suite $result = array(); foreach ($bookings as $booking) : $result[$booking['suite']][] = $booking; endforeach; // create our array for the gantt json feed $json = array(); $count = 0; foreach ($result as $itemName => $rows) : $count++; $customClass = ($count % 2 == 1) ? "ganttRed" : "ganttBlue"; foreach ($rows as $row) : $quantity = array_shift($row['quantity']); $data = [[ 'from' => $row["start_date"], 'to' => $row["end_date"], 'label' => $row['person']." (".$quantity.")", 'desc' => $row['name']."<br/>".$row['telephone']."<br/>".$row['email'], 'customClass' => $customClass ]]; $json[] = array( 'name' => $itemName, 'desc' => 'Booking #'.$row["booking_id"], 'values' => $data ); endforeach; endforeach; The only downside, is that the name column outputs each time: [ { "name":"Suite 1", "desc":"Booking #835", "values":[ { "from":"09\/08\/2022", "to":"09\/14\/2022", "label":"Single Room", "desc":"john@smith.com", "customClass":"ganttRed" } ] }, { "name":"Suite 1", "desc":"Booking #833", "values":[ { "from":"09\/06\/2022", "to":"09\/09\/2022", "label":"Ensuite", "desc":"fred@west.com", "customClass":"ganttRed" } ] } ] What I'd like is the following: [ { "name":"Suite 1", "desc":"Booking #835", "values":[ { "from":"09\/08\/2022", "to":"09\/14\/2022", "label":"Single Room", "desc":"john@smith.com", "customClass":"ganttRed" } ] }, { "name":"", "desc":"Booking #833", "values":[ { "from":"09\/06\/2022", "to":"09\/09\/2022", "label":"Ensuite", "desc":"fred@west.com", "customClass":"ganttRed" } ] } ] I wonder how I may go about achieving this please?
  12. Many thanks for the help. I'm trying to resolve the issue using SQL to help prevent filtering many results. Due to the way the data is stored, it's a little fiddly but will try to fathom it out. The help on here is always very much appreciated Thanks again
  13. I'm using some jQuery to refresh the script every minute or so So in theory, it should mean if someone left the page open, once it refreshes, it will remove any out of date files
  14. Thanks @Barand I realised my naming convention wasn't the best. Therefore, I updated the original post code as $todays_date was a misleading name. This actually refers to the date associated to the file and not the actual date of today - if that makes sense? Apologies, I caused the confusion! I've also amended the code as per your comments. Sadly, I still have the issue
  15. Good afternoon, I've got myself in a muddle over what I thought should be some simple code. Files are uploaded in a CMS and have a date field next to them (returning in format of d/m/Y). So when a new file is added, the user selects the day the file(s) should display For example: File A - 23/08/2022 File B - 24/08/2022 File C - 25/08/2022 Files for the previous day need to display on the current day until a set time (in this instance 13:59:59) I've setup some code as follows: $yesterday = new DateTime("yesterday 13:59:59", new DateTimeZone('Europe/London')); echo "Yesterday " . $yesterday->format('d/m/Y H:i:s') . "<br/>"; date_default_timezone_set('Europe/London'); echo "Today " . date("d/m/Y h:i:s") . "<br/>"; $tomorrow = new DateTime("tomorrow 00:00:01", new DateTimeZone('Europe/London')); echo "Tomorrow " . $tomorrow->format('d/m/Y H:i:s') . "<br/>"; So currently, this outputs: Yesterday 23/08/2022 13:59:59 Today 24/08/2022 02:37:08 Tomorrow 25/08/2022 00:00:01 The above I use to check the date/times whilst I play around with the code logic. I then loop through the uploaded files and dates from the CMS. In the loop, I grab the date (stored as d/m/Y) next to each file so therefore adjust it: $file_date = DateTime::createFromFormat('d/m/Y', $date); Then within the loop, I also add a check to display the file if its the right day/time range: #if today is greater than yesterday but less than tomorrow if($file_date->format('d/m/Y H:i:s') > $yesterday->format('d/m/Y H:i:s') && $file_date->format('d/m/Y H:i:s') < $tomorrow->format('d/m/Y H:i:s') ): //display the file URL endif; It then shows File A and File B but surely should only show File A as it's after Yesterday 23/08/2022 13:59:59 I think I've missed something really obvious but can't see for looking!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.