Skip to content

Instantly share code, notes, and snippets.

@twentyfortysix
twentyfortysix / .htaccess
Created February 27, 2024 11:11
turn off php cache, websupport
php_flag opcache.enable Off
@twentyfortysix
twentyfortysix / wp-inout.sh
Last active January 18, 2024 22:58
partial WP export-import
# Export each post individually
POST_IDS=$(wp post list --post_type=locations --meta_key=page_subtype --meta_value=event --format=ids)
for ID in $POST_IDS; do
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
wp export --dir=export --post__in=$ID
mv export/doprcenakole.wordpress.*.xml export/${TIMESTAMP}.xml
done
# Switch to the other WordPress installation
cd /path/to/other/wordpress/installation
@twentyfortysix
twentyfortysix / .htaccess
Last active February 8, 2024 13:01
header revalidation
## EXPIRES HEADER CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control "max-age=0, no-cache, must-revalidate"
</IfModule>
@twentyfortysix
twentyfortysix / gist:ad79523b60700312b01c8f659630d56c
Created October 2, 2023 16:08
post2post_wp-cli_connections.sh
# bin/bash
for LOCATION in $(wp post list --post_type=locations --posts_per_page=-1 --format=ids); do
for PARTNER in $(wp post list --post_type=partners --connected_type=page2page --connected_items=$LOCATION --nopaging=true --posts_per_page=100 --format=ids); do
wp post delete $PARTNER --force
done
done
browser-sync start --proxy "http://localhost:8080" --files "**/*" --no-notify
@twentyfortysix
twentyfortysix / .htaccess
Last active January 16, 2023 16:18
manual web root to bedrock.sh
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.rocks$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.rocks$
RewriteCond %{REQUEST_URI} !bedrock/web/
RewriteRule (.*) /bedrock/web/$1 [L]
# or
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.rocks$
#recover previous db backup, not last!
cd db_backup && wp db import "$(print -lr -- **/*(om[2,2]))"
wp db drop --yes && wp db import $(find db_backup/* -printf '%T+ %p\n' | sort -r | head -n 1)
@twentyfortysix
twentyfortysix / acf_meta_to_relation.php
Last active October 20, 2021 16:34
first function migrates the simple id to acf relation array, second cleans the data
<?php
function addMetaId2Relations($post_type, $meta_from, $meta_to){
$arr = [
'post_type' => $post_type,
'posts_per_page' => -1,
'fields' => 'ids'
];
$q = new WP_Query($arr);
echo 'poluted:<br><br>';
foreach ($q->posts as $id) {