Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Posts posted by jarvis

  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. 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?

  3. 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?

  4. 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

  5. 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

  6. 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!?

  7. 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?

  8. 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

  9. 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

  10. 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!

  11. The site is a Wordpress site and uses a plugin. Basically, it adds a dropdown of fontawesome icons against the taxonomy field. You select the icon, click save and the data is stored in the termemta table. The meta_key is icon and the meta_value looks like:

    { "style" : "regular", "id" : "circle-dot", "label" : "Circle dot", "unicode" : "f192" }

    It would make sense to escape the data when storing.

    If I access the value direct from the database, it shows as: f192

    It therefore seems to be once the code is passed to the encoding aspect that it throws a wobbly and adds the slashes

  12. Thanks @mac_gyver I see RE the JSON_UNESCAPED_SLASHES 

    If I simply set the code to:

    	$pin_color = '#f76458';
    	$icon_color = '#000';
    	$icon = "\u{f57f}";

    Then the return data is:

    "pin_color":"#f76458","icon_color":"#000","icon":"\uf57f"

    Which works.

    If I amend the code to:

    if (!empty($child_icon)) :
    	$pin_color = $child_pin_colour;
    	$icon_color = $child_icon_colour;
    	$icon = "\u{f57f}";
    elseif (!empty($parent_icon)) :
    	$pin_color = $parent_pin_colour;
    	$icon_color = $parent_icon_colour;
    	$icon = "\u{f57f}";
    else:
    	$pin_color = '#f76458';
    	$icon_color = '#000';
    	$icon = "\u{f57f}";
    endif;

    This also works, showing the different pin/marker colours and the same icon.

    It just seems to be when getting the value from the DB for $icon it doesn't work.

  13. Thanks @mac_gyver

    I've tried both: 

    $json_data = json_encode($json,JSON_UNESCAPED_UNICODE); 

    And

    $json_data = json_encode($json,JSON_UNESCAPED_SLASHES); 

    In both instances, it still seems to return:

    "pin_color":"#dd9933","icon_color":"#ffffff","icon":"\\f192"

    This is before I even try to do anything to get the value into the format I need (\u{f192})

  14. Thanks @ginerjm

    Apologies, wasn't doubting your code  at all.

    Ok, so the database stores the data like so:

    { "style" : "regular", "id" : "circle-dot", "label" : "Circle dot", "unicode" : "f192" }

    If I output (echo) the unicode value (which is the one I need), it always returns the value as: \f192

    If I check the JSON being created, the value already changes to: 

    "pin_color":"#dd9933","icon_color":"#ffffff","icon":"\\f192"

    I only have the code as per the above, so something is clearly causing an issue.

     

    With regards to the '$child_icon anywhere else but the very first line of your example', this is fine. Basically, the code has 3 levels it checks through: child, parent then default

    This is a Wordpress site you see and the values are stored against taxonomies. It checks the child value, if it has a value it's displayed, if it's empty, it checks the parent value and displays it, if that's also empty, it displays the default.

    Only the initial code needs this, as it determines which value is passed through the JSON and therefore displayed on the map - I possibly haven't explained that very well!

  15. Many thanks for the replies. Sadly, none of those seem to work.

    In answer to @ginerjm, the value is being pulled from a database field ($child_icon) It's part of conditional:

    if (!empty($child_icon)) :
    	$pin_color = $child_pin_colour;
    	$icon_color = $child_icon_colour;
    	$icon = $c_icon;
    elseif (!empty($parent_icon)) :
    	$pin_color = $parent_pin_colour;
    	$icon_color = $parent_icon_colour;
    	$icon = $p_icon;
    else:
    	$pin_color = '#f76458';
    	$icon_color = '#000';
    	$icon = "\u{f57f}";
    endif;

    This is then used in a loop to construct some json:

    			$json[] = array(
    				'lat' 		=> $location['lat'],
    				'lon' 		=> $location['lng'],
    				'title' 	=> $location_title,
    				'html' 		=> $html,
    				'pin_color'	=> $pin_color,
    				'icon_color'=> $icon_color,
    				'icon'		=> $icon
    			);

    Which is then used in the JavaScript: 

    				var loc = {
    					'lat'		: data.lat,
    					'lon'		: data.lon,
    					'html'		: data.html,
    					
    					'icon': {
    						path: MAP_PIN,
    						fillColor: data.pin_color,
    						fillOpacity: 1,
    						strokeColor: '',
    						strokeWeight: 0
    					},	
    					
    					'label': {
    						fontFamily: 'Fontawesome',
    						text: data.icon,
    						fontSize: '18px',
    						color: data.icon_color,
    						className: 'map-label'
    					},
    
    
    				};
    				markers.locations.push(loc);

    Which then outputs custom map markers on a Google Map.

    However, no matter what I try, the output always seems to include a double slash:

    "pin_color":"#dd9933","icon_color":"#ffffff","icon":"\\u{f192}"

    Yet needs to be:

    "pin_color":"#dd9933","icon_color":"#ffffff","icon":"\u{f192}"

    Apologies if you needed the bigger picture from the outset!? But wasn't sure it was needed. With hindsight, perhaps it would help and may have other ways to solve it?

  16. Good Morning,

    I'm trying to do a str_replace on a value but it doesn't seem to return the result I'm after.

    I have $child_icon which has the value of "\\f192"

    What I'm trying to do, is change it to \u{f192

    So thought str_replace would be the best route.

    If I use 

    str_replace('\\', '', $child_icon);

    It returns f192, as I would expect. 

    However, I can't seem to add \u{ at the beginning. 

    str_replace('\\', '\u{', $child_icon);

    Returns \\u{f192

    str_replace('\\', '\\u{', $child_icon);

    Returns \\u{f192

    If I try and set the value as a variable, then amend it, it still isn't right, for example:

    $c_icon = str_replace('\\', '', $child_icon);
    $icon = '\u{f'.$c_icon;

    It still returns \\u{f192

    Am guessing I'm missing something very obvious. Is there another way to do this?

    Any help would be very much appreciated!

    Thanks

  17. Hi,

    I hope someone can help. The following code combines jQuery DataTables and Google Maps to create filtering. This works perfectly.

    What I'm trying to do, due to the volume of data is then include clustering.

    I've got the relevant Clustering incude:

    <script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>

    This is the full code to build the table/map:

    
            var locations = <?php echo $json_data; ?>
    
            $(document).ready(function () {
                // Initialize empty map instance
                var maplace = new Maplace({
                    shared: {
                         zoom: 16
                     },
    				controls_on_map: false,
    				styles: {
    						'Minimal': [{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2f2f2"}]},{"featureType":"poi","elementType":"geometry.fill","stylers":[{"saturation":"-100"},{"lightness":"57"}]},{"featureType":"poi","elementType":"geometry.stroke","stylers":[{"lightness":"1"}]},{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"transit","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels.text","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels.text.fill","stylers":[{"visibility":"off"},{"color":"#484848"}]},{"featureType":"transit","elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels.icon","stylers":[{"visibility":"on"}]},{"featureType":"transit.station.bus","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit.station.bus","elementType":"labels.text.fill","stylers":[{"saturation":"0"},{"lightness":"0"},{"gamma":"1.00"},{"weight":"1"}]},{"featureType":"transit.station.bus","elementType":"labels.icon","stylers":[{"saturation":"-100"},{"weight":"1"},{"lightness":"0"}]},{"featureType":"transit.station.rail","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit.station.rail","elementType":"labels.text.fill","stylers":[{"gamma":"1"},{"lightness":"40"}]},{"featureType":"transit.station.rail","elementType":"labels.icon","stylers":[{"saturation":"-100"},{"lightness":"30"}]},{"featureType":"water","elementType":"all","stylers":[{"color":"#d2d2d2"},{"visibility":"on"}]}]
    				}			
                }).Load();		
    			
    			//new markerClusterer.MarkerClusterer({ locations, maplace });
    
                // Initialize DataTable
                var myTable = $('#mytable').DataTable({
                    data: locations,
                    pageLength: 10,
                    columns: [
                        {data: 'title', title: 'City'},
                        {data: 'lat', title: 'Latitude'},
                        {data: 'lon', title: 'Longitude'},
                    ],
                    columnDefs: [
                        {targets: [0], width: '33%'},
                        {targets: [1], width: '33%'},
                        {targets: [2], width: '33%'},
                    ],
    
                    // When the table is redrawn, update the map with the visible rows
                    drawCallback: function(settings) {
                        var api = this.api();
    
                        // Clear all markers when table is redrawn
                        var markers = {
                            'locations': []
                        };
    
                        // Page: all / search: applied - makes sure all pages are used with the applied filter
                        api.rows({page: 'all', search: 'applied'}).every(function(rowIdx, tableLoop, rowLoop) {
                            var data = this.data();
                            var loc = {
                                'lat': data.lat,
                                'lon': data.lon,
                                'html': data.html,
                                'icon': data.icon
                            };
                            markers.locations.push(loc);
    						//new MarkerClusterer({ markers, maplace });
    
                            var row = this.node();
    
                            $(row).removeClass (function (index, css) {
                                return (css.match (/\brow-\d+/g) || []).join(' ');
                            });
                            $(row).addClass('row-'+ rowLoop);
                        });
    
                        // Load the map
                        maplace.Load({
                            locations: markers.locations						
                        });
    					
    					
    		
                    }
                });				
    
                // Add per column filters
                yadcf.init(myTable, [
                    {
                        column_number: 0
                    }
                ]);
    
                // Add event listener clicking on table and showing on map
                $('#mytable tbody').on('click', '.sorting_1', function () {
                    var tr = $(this).closest('tr');
                    var row = myTable.row(tr);
    
                    // This is our class-populated row number
                    var idx = Number(tr.attr('class').match(/(?:row-)(\d+)/)[1]) + 1;
    
                    // Zoom to clicked record on map
                    maplace.ViewOnMap(idx);
                });
    
    			// Cluster the markers
    			new markerClusterer.MarkerClusterer({ locations, maplace });
            });

    But I can't see how to get the clustering to work?

    I thought I'd be ok so include it and reference the map/markers. Perhaps it's where I've included the call? But I thought being the last part on the script would be the right way to go about it?

  18. Hi All,

    Am hoping someone can help!

    I have a table on my page which has multiple rows. Each row has a button, clicking the button triggers a modal pop up (Bootstrap). Within the modal is various details and a gallery.

    What I'm trying to do, is get the gallery to run as a carousel using Slick Slider.

    My ajax function is below:

    function fetch_post_data(post_id,vids)  {
    	 
    	var action = 'fetch_post_data';				
    	
    	$.ajax({
    		url: blog.ajaxurl, 
    		method: "POST",
    		data: { action:action, post_id:post_id, vids:vids},
    		success: function(data) {
    			$('#productModal').modal('show');
    			$('#post_detail').html(data);
    		}
    	});
    }

    Now, using the following code, I can get the slick slider carousel to work once the modal initially opens:

    $('.modal').on('shown.bs.modal', function () {
      $('.slider-class').slick();
      $('.wrap-modal-slider').addClass('open');
    });

    The issue I'm having, is when you scroll to the next modal (hence using Ajax), the carousel won't run.

    I'm guessing, I need to somehow merge the above function into the success: function(data){} code.

    However, I simply can't get it to work.

    Absolutely any help here  would be ace!

    Thanks

×
×
  • 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.