Skip to content

Instantly share code, notes, and snippets.

<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 / 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
@twentyfortysix
twentyfortysix / custom_excerpt.twig
Created May 7, 2017 17:31
WP - timber custom excerpt
{{ function("strip_tags", post.content)|truncate(50) }}
@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 / 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 / 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 / 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 / .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 / 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 / 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