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
@carlaizumibamford
carlaizumibamford / Resolving Jquery Conflicts (After)
Created February 2, 2022 23:11
Resolving Jquery Conflicts (After)
<?php jQuery(document).ready(function(){
// insert coding here
}); ?>
function modify_post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr) {
$id = get_post_thumbnail_id();
$src = wp_get_attachment_image_src($id, $size);
$alt = get_the_title($id);
$class = $attr['class'];
if (strpos($class, 'retina') !== false) {
$html = '<img src="' . $src[0] . '" alt="' . $alt . '" class="' . $class . '" />';
} else {
$html = '<img src="' . $src[0] . '" alt="' . $alt . '" class="' . $class . '" />';
}
<?php echo the_post_thumbnail('post-thumbnail', array('class' => 'retina additional-class')); ?>
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
Display posts by author, using author id:
$query = new WP_Query( array( 'author' => 123 ) );
Display posts by author, using author ‘user_nicename‘:
$query = new WP_Query( array( 'author_name' => 'rami' ) );
Show Posts From Several Authors
Display posts from several specific authors:
$query = new WP_Query( array( 'author' => '2,6,17,38' ) );
Display posts that have one category (and any children of that category), using category id:
$query = new WP_Query( array( 'cat' => 4 ) );
Display posts that have this category (and any children of that category), using category slug:
$query = new WP_Query( array( 'category_name' => 'staff' ) );
Display posts that have this category (not children of that category), using category id:
$query = new WP_Query( array( 'category__in' => 4 ) );
Display posts that have several categories, using category id:
Display posts that have one tag, using tag slug:
$query = new WP_Query( array( 'tag' => 'cooking' ) );
Display posts that have this tag, using tag id:
$query = new WP_Query( array( 'tag_id' => 13 ) );
Display posts that have “either” of these tags:
$query = new WP_Query( array( 'tag' => 'bread,baking' ) );
Display posts that have “all” of these tags:
Display post by ID:
$query = new WP_Query( array( 'p' => 7 ) );
Display page by ID:
$query = new WP_Query( array( 'page_id' => 7 ) );
Show post/page by slug
$query = new WP_Query( array( 'name' => 'about-my-life' ) );
Display page by slug:
// This will NOT work
$exclude_ids = '1,2,3';
$query = new WP_Query( array( 'post__not_in' => array( $exclude_ids ) ) );
// This WILL work
$exclude_ids = array( 1, 2, 3 );
$query = new WP_Query( array( 'post__not_in' => $exclude_ids ) );
Display only password protected posts:
$query = new WP_Query( array( 'has_password' => true ) );
Display only posts without passwords:
$query = new WP_Query( array( 'has_password' => false ) );
Display only posts with and without passwords:
$query = new WP_Query( array( 'has_password' => null ) );
Display posts with a particular password: