Advanced Custom Fields sort by field group sub field

Run a WordPress Query based on Advanced Custom Fields group sub field.

Example

If you have an ACF group labelled “Date and Time” with a name of “date_and_time”. Inside this group you have sub fields called “Date” (date), “Start Time” (start_time) and “End Time” (end_time).

You can pull a query based on the sub fields using the ‘meta_key’ option like this:
date_and_time_date
date_and_time_start_time
date_and_time_end_time

   $args = array(
        'post_type' => 'event',
        'posts_per_page' => -1,
        'meta_key' => 'date_and_time_date',
        'orderby' => 'meta_value',
        'order' => 'ASC'
    );
    $the_query = new WP_Query( $args );

This assumes your Date field has a return format of “Ymd”.

Make HTTPS requests from Arduino using a LoLin NodeMCU board

This had me stumped for a while. Many tutorial around the web show how to pull data from the web using various Arduino boards. They all seemed to be for http not https. Here’s my solution with the relevant https bits highlighted with //***

/*
WebCheck
Grab some data from a webpage generated by php.
The php can do the heavy lifting, just presenting the raw data to the Arduino board.
In this test the php script just echos *sometext*. I'm using * as a bookend to the data I want as I know I will never use * in the data.
If you need some more generic way of processing data then go write some code. 🙂
*/

#include <ESP8266WiFi.h>

#define LED_BUILTIN 2
#define LED_OFF HIGH
#define LED_ON LOW

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const int getDataInterval = 5000; // delay between updates, in milliseconds
unsigned long uptime = 0;
String tempString = "";

WiFiClientSecure client; //*** THIS RIGHT HERE ***

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LED_OFF);
Serial.begin(115200);
Serial.println();

WiFi.begin("SSID", "pwd");

Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
digitalWrite(LED_BUILTIN, LED_ON);
delay(100);
digitalWrite(LED_BUILTIN, LED_OFF);
delay(200);
Serial.print(".");
}
Serial.println();

Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());

digitalWrite(LED_BUILTIN, LED_ON);

}

void loop() {
uptime = millis(); //- Time since board booted in ms

if( uptime - lastConnectionTime >= getDataInterval ) {
lastConnectionTime = uptime;
Serial.println( uptime );
getWebData();
Serial.println( tempString );
}
}

void getWebData(){
char bookend = '*';
int doRead = -1;

client.stop();
tempString = "";

//*** THE PORT NEEDS TO BE 443***
if (client.connect("www.stuartfarish.com", 443)) {
// Make a HTTPS request:
client.println("GET /datawritescript.php HTTP/1.1");
client.println("Host: www.stuartfarish.com");
client.println("Connection: close");
client.println();

//- Grab the data. Ignore everything outside the 'bookend' characters, which is "*".
while (client.connected()) {
char c = client.read();
if(c == bookend) doRead *= -1;
if(doRead == 1 && c != bookend) {
tempString = String(tempString + c);
}
}
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}

Enable swap file on Amazon EC2 instance

This was done on a t2.medium instance with 4GB of RAM and a 50GiB EBS volume. The primary reason was to give the webserver a bit of leeway during high traffic periods. Stops it running out of memory and falling over.

Most of this is taken from the Amazon docs.

# Create a 6GB swap file
sudo dd if=/dev/zero of=/swapfile bs=1G count=6

#Update the permissions
sudo chmod 600 /swapfile

#Set up the swap
sudo mkswap /swapfile

#Make the swap available
sudo swapon /swapfile

#Enable swap at boot
sudo nano /etc/fstab

#Add this line at the bottom
/swapfile swap swap defaults 0 0

Hide website listing in Amazon EC2 AMI

By default Amazon’s AMI allows directory listings for your website. In WordPress this exposes you /wp-content/uploads folder to the web. Not a big deal but could be a security risk if you upload anything sensitive to your site for some reason. You need to change the default httpd.conf file:

sudo nano /etc/httpd/conf/httpd.conf

Change the following line:

Options Indexes FollowSymLinks

to

Options FollowSymLinks

as shown below (I’ve left the original line commented out)

# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
#Options Indexes FollowSymLinks
Options FollowSymLinks

Restart your webserver:

sudo service httpd restart