Skip to content

Instantly share code, notes, and snippets.

@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 "================================================================="
@twentyfortysix
twentyfortysix / register_media_field.php
Last active February 15, 2016 13:07
WP - register custom field for media
<?php
function be_attachment_field_credit( $form_fields, $post ) {
//
// ---- CS ---
//
$form_fields['media_date'] = array(
'label' => 'Datum',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'media_date', true ),
// 'helps' => 'datace',
@twentyfortysix
twentyfortysix / wp-cli.shell
Created February 13, 2016 19:36
wp-cli - initial live saver
wp plugin install custom-content-type-manager simple-image-sizes codepress-admin-columns adminimize