Skip to content

Instantly share code, notes, and snippets.

View carlaizumibamford's full-sized avatar
💭
I may be slow to respond.

CARLA I. BAMFORD carlaizumibamford

💭
I may be slow to respond.
View GitHub Profile
Show Posts based on a keyword search
$query = new WP_Query( array( 's' => 'keyword' ) );
Display posts with 20 comments:
$args = array(
'post_type' => 'post',
'comment_count' => 20,
);
$query = new WP_Query( $args );
Display posts with 25 comments or more:
$args = array(
'post_type' => 'post',
Display published and private posts, if the user has the appropriate capability:
$args = array(
'post_status' => array( 'publish', 'private' ),
'perm' => 'readable',
);
$query = new WP_Query( $args );
Get attachments that are gif images:
Get gif images and remember that by default the attachment’s post_status is set to inherit.
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => 'image/gif',
);
$query = new WP_Query( $args );
Show Posts without adding post information to the cache
Display 50 posts, but don’t add post information to the cache
$args = array(
'posts_per_page' => 50,
'cache_results' => false
);
$query = new WP_Query( $args );
Show Posts without adding post meta information to the cache
Display 50 posts, but don’t add post meta information to the cache:
@carlaizumibamford
carlaizumibamford / Excluding Posts By Category Name In WordPress
Last active May 11, 2022 01:55
Excluding Posts By Category Name In WordPress
$id = get_cat_id('Category-Sample');
$q = "cat=-" . $id;
query_posts($q);
if (have_posts()) : while (have_posts()) : the_post();
@carlaizumibamford
carlaizumibamford / Making Alternative has_post_thumbnail() In WordPress
Last active May 11, 2022 01:56
Making Alternative has_post_thumbnail() In WordPress
Instead of
if ( has_post_thumbnail() ) {
}
use this code
$featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
if ( ! empty( $featured_image_url ) ) {
}
@carlaizumibamford
carlaizumibamford / Echoing HTML In PHP
Last active May 11, 2022 01:56
Echoing HTML In PHP
// In Between PHP
<?php if(condition){ ?>
HTML
<?php } ?>
// In An PHP
if(condition){
echo "HTML";
}
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 1
Created May 11, 2022 02:09
Creating A Custom Wordpress Widget Plugin Vol 1
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
@carlaizumibamford
carlaizumibamford / Creating A Custom Wordpress Widget Plugin Vol 2
Last active May 11, 2022 18:52
Creating A Custom Wordpress Widget Plugin Vol 2
class My_Custom_Widget extends WP_Widget {
public function __construct() {
}
public function form( $instance ) {
}
public function update( $new_instance, $old_instance ) {
}
public function widget( $args, $instance ) {
}