Skip to content

Instantly share code, notes, and snippets.

@lichtmetzger
lichtmetzger / functions.php
Created May 24, 2023 16:34
Copy old meta fields into new meta fields
<?php
$args = array(
'post_type' => 'events', // Adjust post type if needed
'posts_per_page' => -1, // Retrieve all posts
);
$posts_query = new WP_Query($args);
if ($posts_query->have_posts()) {
while ($posts_query->have_posts()) {
@lichtmetzger
lichtmetzger / snippet.php
Created February 7, 2023 14:41
Copy all taxonomy terms into a new taxonomy and re-set them on all posts
<?php
function convert_tax($post_type, $old_tax, $new_tax) {
$pages = get_posts(array(
'post_type' => $post_type,
// Get all post statuses
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $old_tax,
@lichtmetzger
lichtmetzger / extract.ps
Last active August 30, 2022 17:31
Powershell: 7-Zip parallel extraction from current directory
Get-ChildItem *.7z | foreach-Object -parallel {
& "C:\Program Files\7-Zip\7z.exe" -aoa x $_.FullName -o*
} -ThrottleLimit 10
@lichtmetzger
lichtmetzger / snippet.php
Last active August 9, 2022 12:59
Override meta query
<?php
// META QUERY
function searchExcludeOldMatches( $query ) {
if (!is_admin() && $query->is_search) {
$query->set('meta_query', array(
array(
'key' => 'ctl_visibility',
'value' => 'true',
'compare' => '=',
@lichtmetzger
lichtmetzger / snippet.php
Last active August 9, 2022 12:58
Update meta fields for CPT in WordPress if not set already
<?php
$query = new WP_Query(array(
'post_type' => 'company',
'posts_per_page' => -1
));
$posts = [];
while ($query->have_posts()) {
$query->the_post();