Skip to content

Instantly share code, notes, and snippets.

@ajaydsouza
ajaydsouza / modify-date-columns.sql
Last active October 21, 2024 21:24
WordPress: Set date columns to be CURRENT_TIMESTAMP
ALTER TABLE `wp_posts`
CHANGE `post_date` `post_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CHANGE `post_date_gmt` `post_date_gmt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CHANGE `post_modified` `post_modified` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CHANGE `post_modified_gmt` `post_modified_gmt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
@ajaydsouza
ajaydsouza / add_classes_to_crp_post_class.php
Last active September 3, 2024 16:37
Add styles to Contextual Related Posts output
<?php
function add_classes_to_crp_post_class( $classes ) {
$classes .= ' alignwide';
return $classes;
}
add_filter( 'crp_post_class', 'add_classes_to_crp_post_class' );
@ajaydsouza
ajaydsouza / block-content.js
Created July 24, 2024 16:20
Example of updating block content by filtering editor.BlockListBlock
/*
* This isn't a fully working example yet due to limitations in what is available via BlockListBlock
*/
import { store as coreStore } from '@wordpress/core-data';
import { useState, useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { useBlockProps } from '@wordpress/block-editor';
import apiFetch from '@wordpress/api-fetch';
import { addFilter } from '@wordpress/hooks';
@ajaydsouza
ajaydsouza / rules.v4
Created July 26, 2023 20:26
Oracle iptables default rules
# CLOUD_IMG: This file was created/modified by the Cloud Image build process
# iptables configuration for Oracle Cloud Infrastructure
# See the Oracle-Provided Images section in the Oracle Cloud Infrastructure
# documentation for security impact of modifying or removing these rule
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [463:49013]
<?php
// The Query.
$the_query = new Top_Ten_Query( $args );
// The Loop.
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
@ajaydsouza
ajaydsouza / standard-loop.php
Last active January 10, 2021 14:53
CRP_Query Examples
<?php
// The Query.
$the_query = new CRP_Query( $args );
// The Loop.
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
@ajaydsouza
ajaydsouza / bsearch-html-markup.html
Created June 3, 2019 21:41
Better Search HTML markup
<!-- This is the sample markup generated by Better Search v2.3.0 for each article entry -->
<article id="post-1011" class="bsearch-post post-1011 post type-post status-publish format-standard has-post-thumbnail hentry category-codex category-corner-case category-featured-images category-images">
<header class="bsearch-entry-header">
<h2 class="bsearch-entry-title"><a href="https://wpnetwork.local/blog/featured-image-horizontal/" rel="bookmark">Featured Image (Horizontal)</a></h2>
<p><span class="bsearch_score">Relevance: 75%</span> &nbsp;&nbsp;&nbsp;&nbsp; <span class="bsearch_date">Posted on: March 15, 2013</span></p>
</header>
<div class="bsearch-entry-content">
@ajaydsouza
ajaydsouza / tptn-restyle-count.php
Last active December 21, 2018 18:39
Convert Top 10 count to use k, m and bn
<?php
/**
* Modify the display the tptn counter to show k and m instead.
*
* Add this code to your theme's functions.php file or in a file in mu-plugins.
*
* @param $string $input Formatted list count
*/
function tptn_restyle_count( $input ) {
@ajaydsouza
ajaydsouza / crp_change_query_dates.php
Created November 18, 2018 12:38
Filter from and now date in Contextual Related Posts
<?php
/**
* Filter crp_posts_from_date.
*
* @param string $where The Minimum date of the WHERE clause of the query.
* @param int $id Post ID
*/
function crp_same_date_from( $where, $id ) {
global $wpdb, $post;
@ajaydsouza
ajaydsouza / crp-vertical.css
Last active November 6, 2017 22:42
Contextual Related Posts styles
/* Vertical Related Posts */
/* The full list */
.crp_related ul li {
list-style-type:none;
/* float:left; */
margin:0 40px 0 0;
width: 230px;
}