Skip to content

Instantly share code, notes, and snippets.

@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
@twentyfortysix
twentyfortysix / examle.twig
Last active April 7, 2018 08:37
frontpage.twig
{% extends 'base.twig' %}
{% import 'macro/edit-link.twig' as editLink %}
{% block content %}
{% for view in post.get_field('flexible_content') %}
{# guides #}
{% if view.acf_fc_layout == "guides" %}
<div class="container {{ view.acf_fc_layout }}">
<div class="row">
{% for item in view.guide %}
@twentyfortysix
twentyfortysix / twig_excerpt.twig
Last active December 2, 2020 15:22
WP - manual clean timber excerpt
{# beware of gallery shortcodes #}
{% set content = function('strip_shortcodes', item.get_preview(80,false,"",true)) %}
{# strip tags #}
{{ function("strip_tags", post.content)|truncate(50) }}
{{ content|striptags|truncate(50) }}
function custom_trim($value, $limit = 100, $end = '...'){
$value = strip_tags($value);
if (mb_strwidth($value, 'UTF-8') <= $limit) {
@twentyfortysix
twentyfortysix / bulk_post_meta_update.php
Created May 14, 2017 16:15
WP - bulk update post meta
<?php
function _run_once(){
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'place'
)
);
foreach($posts as $p) :
// $meta = get_post_meta($p->ID, 'advertiser_type',true);
@twentyfortysix
twentyfortysix / wp_cli_generate_posts
Created May 11, 2017 12:16
WP - generate some dummy posts
curl "http://loripsum.net/api/5/medium/decorate/link/ul/ol/dl/bq/code/headers/" | sed "s/<\/p>/<\/p>/" | wp post generate --post_content --count=10
@twentyfortysix
twentyfortysix / custom_excerpt.twig
Created May 7, 2017 17:31
WP - timber custom excerpt
{{ function("strip_tags", post.content)|truncate(50) }}
@twentyfortysix
twentyfortysix / bulk_category_remover.php
Created May 2, 2017 15:19
WP - bulk remove category
<?php
add_action( 'init', function()
{
// Get all the posts which is assigned to the uncategorized category
$args = array(
'post_type' => 'cp_crq_news',
'posts_per_page' => -1, // Adjust as needed
'cat' => 84, // Category ID for uncategorized category
'fields' => 'ids', // Only get post ID's for performance
// Add any additional args here, see WP_Query
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<link rel="stylesheet" href="mystyle.css" >
<style>
.circle{
height:200px;
width:200px;
background-color: red;
border:1px solid green;
@twentyfortysix
twentyfortysix / multiple_meta_query_sorting.php
Last active May 19, 2023 14:23
WP - sort by date and time custom values
'meta_query' => [
'date_' => [
'key' => 'start_date',
'compare' => 'EXISTS',
],
'time_' => [
'key' => 'start_time',
'compare' => 'EXISTS',
],
],
@twentyfortysix
twentyfortysix / fire_up_wp.sh
Last active April 17, 2016 15:06
initial wp installation
!/bin/bash -e
#modified to personal user by 2046, original - https://www.ltconsulting.co.uk/automated-wordpress-installation-with-bash-wp-cli/
wpuser='2046'
clear
echo "================================================================="
echo "Awesome WordPress Installer!!"
echo "================================================================="