This example illustrates how to query an array of post IDs from a custom DB table then use the array in a WP_Query.
This can be much faster than using meta queries on a WP_Query object, particularly if you are matching multiple fields.
| <?php | |
| /** | |
| * Class Dump | |
| * A simple static class for dumping data to a separate log file to aid debugging and development. | |
| * | |
| * @author Phil Kurth <[email protected]> | |
| */ | |
| class Dump { |
| alias wp-update-all="wp plugin update --all && wp language plugin update --all && wp theme update --all && wp language theme update --all && wp core update --force && wp language core update" | |
| <?php | |
| /* | |
| * This is a rather simple and contrived example but it illustrates how this | |
| * function can be used to temporarily change the post context. | |
| */ | |
| $alt_post_content = override_post_context( 1234, function ( $post ) { | |
| ob_start(); | |
| // Do whatever you need here. The $post variable, in this scope, is the |
| <?php | |
| add_action( 'wp_enqueue_scripts', function () { | |
| $uri = get_stylesheet_directory_uri(); | |
| $dir = get_stylesheet_directory(); | |
| $script_last_updated_at = filemtime( "$dir/scripts/my-script.js" ); | |
| $style_last_updated_at = filemtime( "$dir/styles/my-style.css" ); |
| module.exports = { | |
| generateId: function() { | |
| // Generate a semi-unique id | |
| return '_' + Math.random().toString(36).substr(2, 9); | |
| }, | |
| byteToString: function(blob) { | |
| // Turn an arraybuffer into a base64 string | |
| return btoa(new Uint8Array(blob).reduce(function (data, byte) { | |
| return data + String.fromCharCode(byte); | |
| }, '')) |
| <?php | |
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use Illuminate\Support\Facades\DB; | |
| use Illuminate\Support\Facades\Storage; | |
| class SnapshotCommand extends Command | |
| { |
| <?php | |
| add_action( 'init', function() { | |
| /** | |
| * 1. PHP adds the variable into the symbols table. | |
| * 2. PHP adds the value into the data table, which is called zval. | |
| * 3. PHP points the value location to the variable location, binding them together. | |
| * 4. refcount is incremented to 1. | |
| */ |