Skip to content

Instantly share code, notes, and snippets.

View onurguven's full-sized avatar
🎯
Focusing

Onur onurguven

🎯
Focusing
View GitHub Profile
@luetkemj
luetkemj / wp-query-ref.php
Last active May 25, 2024 10:56
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
@billerickson
billerickson / gist:2047229
Last active July 10, 2023 22:04
Improve performance of WP_Query
<?php
$args = array(
// Normal query goes here //
'no_found_rows' => true, // counts posts, remove if pagination required
'update_post_term_cache' => false, // grabs terms, remove if terms required (category, tag...)
'update_post_meta_cache' => false, // grabs post meta, remove if post meta required
);
@maxxscho
maxxscho / functions.php
Created March 17, 2012 12:48
Wordpress: Shortcode Empty Paragraph fix
function shortcode_empty_paragraph_fix($content)
{
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
@Narga
Narga / wordpress-list-most-recent-comments.php
Created June 7, 2012 02:05
Wordpress - List most recent comments
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "n<ul>";
foreach ($comments as $comment) {
$output .= "n<li>".strip_tags($comment->comment_author) .":" . "<a href="" . get_permalink($comment->ID)."#comment-" . $comment->comment_ID . "" title="on ".$comment->post_title . "">" . strip_tags($comment->com_excerpt)."</a></li>";
}
@RalfAlbert
RalfAlbert / filters-for-simple-cache-template.php
Created June 7, 2012 23:53
Page template for WordPress with caching
<?php
add_action( 'save_post', 'clear_many_sites_transient', 10, 1 );
add_action( 'edit_post', 'clear_many_sites_transient', 10, 1 );
function clear_many_sites_transient( $post_id ){
$post = get_post( $post_id );
if( 'page' === $post->post_type )
delete_transient( 'many_sites_in_one' );
@c3mdigital
c3mdigital / class-simple-local-avatars.php
Created June 24, 2012 04:53
Upload custom avatars for users to override gravatar for comments and author_meta
<?php
/*
Plugin Name: Custom WordPress Avatars
Plugin URI: http://c3mdigital.com
Description: Adds a custom avatar uploader in the user profile to replace gravatars with a custom avatar
Version: 1.0
Author: Chris Olbekson
Author URI: http://c3mdigital.com/
License: GPL v2
*/
@JimWestergren
JimWestergren / index-with-redis.php
Last active February 11, 2023 18:28
Redis as a Frontend Cache for WordPress
<?php
/*
Author: Jim Westergren & Jeedo Aquino
File: index-with-redis.php
Updated: 2012-10-25
This is a redis caching system for wordpress.
see more here: www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/
@Abban
Abban / facebook-url-parse.php
Created June 19, 2013 17:54
Code To parse FB url and Twitter username
<?
protected function valid_facebook_url($field){
if(!preg_match('/^(http\:\/\/|https\:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w\.)*#!\/)?(?:pages\/)?(?:[\w\-\.]*\/)*([\w\-\.]*)/', $field)){
return false;
}
return true;
}
@bcole808
bcole808 / get_cached_template_part.php
Created March 5, 2014 17:23
Wordpress template part caching system. Allows parts of a Wordpress template to be stored as site transients in order to speed up the rendering of your theme template parts.
<?php
/**
* Retrieves a template part and caches the output to speed up site
* NOTE: Because we are caching display of posts, we need to make sure to delete the transients when posts are updated or published that might affect these template parts.
*
* Uses this function in conjunction with the WP cache: http://codex.wordpress.org/Function_Reference/get_template_part
*
* @param $slug (string) (required) The slug name for the generic template.
* @param $name (string) (optional) The name of the specialized template.
* @return (string) HTML output of the template part.
@dbranes
dbranes / functions.php
Last active November 3, 2017 12:56
Multiple comment forms and lists in single.php - wpquestions.com #9749
/**
* Example how to setup up multiple comment forms and comments lists
*
* @version 0.0.5
* @file functions.php
* @see http://www.wpquestions.com/question/showLoggedIn/id/9749
*/
/**