Skip to content

Instantly share code, notes, and snippets.

@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) {
@twentyfortysix
twentyfortysix / composer.json
Last active January 3, 2024 16:41
Wordpress Bedrock composer settings
{
"name": "roots/bedrock",
"type": "project",
"license": "MIT",
"description": "WordPress boilerplate with modern development tools, easier configuration, and an improved folder structure",
"homepage": "https://roots.io/bedrock/",
"authors": [
{
"name": "Scott Walkinshaw",
"email": "[email protected]",
{{ fn('wpcf7_contact_form_tag_func', {'id':view.cform7_id, 'html_class':view.css_class}, null, 'contact-form-7') }}
.delayer(@i) when (@i > 0) {
@t: ~":nth-child(@{i})";
li@{t} {
a{
transition: transform .6s ease-out @menu_speed+(@i * @menu_speed), opacity .6s ease-out @menu_speed + (@i * @menu_speed);
}
}
.delayer(@i - 1);
}
@twentyfortysix
twentyfortysix / fetch_token.php
Last active March 5, 2021 14:21
heds up.. wp_remote_post, the Wordpress way
<?php
function get_POI_token($POI_URL_BASE, $POI_URL_TOKEN, $POI_PASS, $POI_USER, $POI_ID, $POI_SECRET){
// do your houseworks..
$url = $POI_URL_BASE.$POI_URL_TOKEN;
$username = $POI_USER;
$password = $POI_PASS;
$client_id = $POI_ID;
$client_secret = $POI_SECRET;
// some wanted url encoded
$args = array(
for POST in $(wp post list --post_type=locations --post_parent=0 --format=ids); do wp post create --post_type=locations --post_parent=$POST --from-post=17717 --post_status=publish; done
<?php
// 1, 2, asc
usort($mix, function ($item1, $item2) {
return $item1->post_date <=> $item2->post_date;
});
@twentyfortysix
twentyfortysix / recently_commented_posts.php
Created February 15, 2021 23:22
php, enclosure, timber, comments
<?php
$args = array(
'status' => 'approve',
'number' => 30,
'order' => 'DESC'
);
$comments = get_comments($args);
$post_ids = array_map(function($key, $value) {
return $value->comment_post_ID;
}, array_keys($comments), $comments);
{{ constant('Twig_Environment::VERSION') }}
@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 );