Skip to content

Instantly share code, notes, and snippets.

@twentyfortysix
twentyfortysix / importer.php
Created August 26, 2020 17:22
import post images to acf gallery
<?php
// field id must be the ACF ID
function post_images_to_ACF_gallery($post_type, $field_id){
$args = array(
'post_status' => 'publish',
'post_type' => $post_type,
'posts_per_page' => -1,
'fields' => 'ids'
);
$the_query = new WP_Query( $args );
<script>
jQuery(document).ready(function($) {
function findCommonElement(filters,classes) {
var result = true;
for(let i = 0; i < filters.length; i++) {
if(!classes.includes(filters[i])){
result = false;
break;
}
}
<?php
function replacer($post_type, $field, $find, $replace, $wet){
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1,
'post_status' => 'any'
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) {
while ( $the_query->have_posts() ) {
@twentyfortysix
twentyfortysix / divide-loop.twig
Created January 27, 2020 18:11
divide for loop by n
{% for col in posts|batch((posts|length / 2)|round(0, 'ceil')) %}
<div class="col-12 col-sm-6">
{% for item in col %}
<a href="{{ item.link }}">
{{ item.title }}
</a>
{% endfor %}
</div>
{% endfor %}
for POST in $(wp post list --post_type=post --category_name=tiskovky --format=ids); do wp post update $POST --post_type=tiskovky; done
for POST in $(wp post list --post_type=locations --meta_key=page_subtype --meta_value=event --format=ids); do wp post update $POST --post_status=draft; done
@twentyfortysix
twentyfortysix / getAndCacheJson.php
Created July 31, 2018 21:35
WP - get and cache json
function get_json($url,$id){
$_url = $url.$id;
$transient = get_transient( $_url );
if(!empty($transient)){
return $transient;
}else{
$request = wp_remote_get( $_url );
if( is_wp_error( $request ) ) {
return false; // Bail early
@twentyfortysix
twentyfortysix / wp-cli-delete-posts-by-meta
Last active April 1, 2021 11:32
wp-cli - delete post by meta
for POST in $(wp post list --post_type=locations --meta_key=page_subtype --meta_value=event --format=ids); do wp post delete $POST --force; done
@twentyfortysix
twentyfortysix / wp-cli-bulk-update-meta
Last active June 19, 2018 14:05
wp-cli - bulk update meta
// erase post meta
for id in $(wp post list –post_type=’locations’ –format=ids); do wp post meta update $id print_textarea ''; done
@twentyfortysix
twentyfortysix / .htaccess
Created June 14, 2018 10:36
show php errors
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on