WordPress Query Reference

/**
* 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
*/
// Author Parameters – Show posts associated with certain author.
// http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters

$args = array(
'author' => '1,2,3,', // (int | string) - use author id or comma-separated list of IDs [use minus (-) to exclude authors by ID ex. 'author' => '-1,-2,-3,']
'author_name' => 'luetkemj', // (string) - use 'user_nicename' (NOT name)
'author__in' => array( 2, 6 ), // (array) - use author id (available with Version 3.7).
'author__not_in' => array( 2, 6 ), // (array)' - use author id (available with Version 3.7).

// Category Parameters - Show posts associated with certain categories.
// http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
'cat' => 5, // (int) - Display posts that have this category (and any children of that category), using category id.
'cat' => '-12,-34,-56' // Display all posts except those from a category by prefixing its id with a '-' (minus) sign.
'category_name' => 'staff, news', // (string) - Display posts that have these categories (and any children of that category), using category slug.
'category_name' => 'staff+news', // (string) - Display posts that have "all" of these categories, using category slug.
'category__and' => array( 2, 6 ), // (array) - Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6.
'category__in' => array( 2, 6 ), // (array) - Display posts that have this category (not children of that category), using category id.
'category__not_in' => array( 2, 6 ), // (array) - Display posts that DO NOT HAVE these categories (not children of that category), using category id.

// Tag Parameters - Show posts associated with certain tags.
// http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
'tag' => 'cooking', // (string) - use tag slug.
'tag_id' => 5, // (int) - use tag id.
'tag__and' => array( 2, 6), // (array) - use tag ids.
'tag__in' => array( 2, 6), // (array) - use tag ids.
'tag__not_in' => array( 2, 6), // (array) - use tag ids.
'tag_slug__and' => array( 'red', 'blue'), // (array) - use tag slugs.
'tag_slug__in' => array( 'red', 'blue'), // (array) - use tag slugs.

// Taxonomy Parameters - Show posts associated with certain taxonomy.
// http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
// Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays)
// This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy queries.
'tax_query' => array( // (array) - use taxonomy parameters (available with Version 3.1).
'relation' => 'AND', // (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. Default value is 'AND'.
array(
'taxonomy' => 'color', // (string) - Taxonomy.
'field' => 'slug', // (string) - Select taxonomy term by Possible values are 'term_id', 'name', 'slug' or 'term_taxonomy_id'. Default value is 'term_id'.
'terms' => array( 'red', 'blue' ), // (int/string/array) - Taxonomy term(s).
'include_children' => true, // (bool) - Whether or not to include children for hierarchical taxonomies. Defaults to true.
'operator' => 'IN' // (string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND', 'EXISTS' and 'NOT EXISTS'. Default value is 'IN'.
),
array(
'taxonomy' => 'actor',
'field' => 'id',
'terms' => array( 103, 115, 206 ),
'include_children' => false,
'operator' => 'NOT IN'
)
),

// Post & Page Parameters - Display content based on post and page parameters.
// http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
'p' => 1, // (int) - use post id.
'name' => 'hello-world', // (string) - use post slug.
'title' => 'Hello World' // (string) - use post title (available with Version 4.4)
'page_id' => 1, // (int) - use page id.
'pagename' => 'sample-page', // (string) - use page slug.
'pagename' => 'contact_us/canada', // (string) - Display child page using the slug of the parent and the child page, separated ba slash
'post_name__in' => 'sample-post' (array) // - use post slugs. Specify posts to retrieve. (available since Version 4.4)
'post_parent' => 1, // (int) - use page id. Return just the child Pages. (Only works with heirachical post types.)
'post_parent__in' => array(1,2,3) // (array) - use post ids. Specify posts whose parent is in an array. NOTE: Introduced in 3.6
'post_parent__not_in' => array(1,2,3), // (array) - use post ids. Specify posts whose parent is not in an array.
'post__in' => array(1,2,3), // (array) - use post ids. Specify posts to retrieve. ATTENTION If you use sticky posts, they will be included (prepended!) in the posts you retrieve whether you want it or not. To suppress this behaviour use ignore_sticky_posts
'post__not_in' => array(1,2,3), // (array) - use post ids. Specify post NOT to retrieve.
// NOTE: you cannot combine 'post__in' and 'post__not_in' in the same query

// Password Parameters - Show content based on post and page parameters. Remember that default post_type is only set to display posts but not pages.
// http://codex.wordpress.org/Class_Reference/WP_Query#Password_Parameters
'has_password' => true, // (bool) - available with Version 3.9
// true for posts with passwords;
// false for posts without passwords;
// null for all posts with and without passwords
'post_password' => 'multi-pass', // (string) - show posts with a particular password (available with Version 3.9)

// Post Type Parameters - Show posts associated with certain type or status.
// http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
'post_type' => array( // (string / array) - use post types. Retrieves posts by Post Types, default value is 'post';
'post', // - a post.
'page', // - a page.
'revision', // - a revision.
'attachment', // - an attachment. The default WP_Query sets 'post_status'=>'published', but atchments default to 'post_status'=>'inherit' so you'll need to set the status to 'inherit' or 'any'.
'nav_menu_item' // - a navigation menu item
'my-custom-post-type', // - Custom Post Types (e.g. movies)
),
// NOTE: The 'any' keyword available to both post_type and post_status queries cannot be used within an array.
'post_type' => 'any', // - retrieves any type except revisions and types with 'exclude_from_search' set to true.

// Post Status Parameters - Show posts associated with certain type or status.
// http://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters
'post_status' => array( // (string | array) - use post status. Retrieves posts by Post Status, default value i'publish'.
'publish', // - a published post or page.
'pending', // - post is pending review.
'draft', // - a post in draft status.
'auto-draft', // - a newly created post, with no content.
'future', // - a post to publish in the future.
'private', // - not visible to users who are not logged in.
'inherit', // - a revision. see get_children.
'trash', // - post is in trashbin (available with Version 2.9).
),
// NOTE: The 'any' keyword available to both post_type and post_status queries cannot be used within an array.
'post_status' => 'any', // - retrieves any status except those from post types with 'exclude_from_search' set to true.

// Comment Paremters - @since Version 4.9 Introduced the `$comment_count` parameter.
// https://codex.wordpress.org/Class_Reference/WP_Query#Comment_Parameters
'comment_count' => 10 // (int | array) The amount of comments your CPT has to have ( Search operator will do a '=' operation )
'comment_count' => array(
'value' => 10 // (int) - The amount of comments your CPT has to have when comparing
'compare' => '=' // (string) - The search operator. Possible values are '=', '!=', '>', '>=', '<', '<='. Default value is '='. ) // Pagination Parameters //http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters 'posts_per_page' => 10, // (int) - number of post to show per page (available with Version 2.1). Use 'posts_per_page' => -1 to show all posts.
// Note: if the query is in a feed, wordpress overwrites this parameter with the stored 'posts_per_rss' option. Treimpose the limit, try using the 'post_limits' filter, or filter 'pre_option_posts_per_rss' and return -1
'nopaging' => false, // (bool) - show all posts or use pagination. Default value is 'false', use paging.
'paged' => get_query_var('paged'), // (int) - number of page. Show the posts that would normally show up just on page X when usinthe "Older Entries" link.
// NOTE: Use get_query_var('page'); if you want your query to work in a Page template that you've set as your static front page. The query variable 'page' holds the pagenumber for a single paginated Post or Page that includes the

Pages: 1 2 3

Quick and Practical CSS Cheat Sheet

Cascading Style Sheets, or CSS for short, is a style sheet language written in a markup language. CSS defines the presentation, look and formatting elements of Web documents, such as the layout, colors and fonts.

CSS syntax is comprehensive, and it is not easy to always know the exact syntax, or know all the available CSS properties and corresponding values. To help CSS developers and designers, Toptal created a quick reference guide and offered it to the community as a free download. The CSS reference guide includes CSS syntax, the most important selectors, properties, sizes and units, and other useful CSS information in a short and informative format. We hope you will find the CSS cheat sheet a valuable resource.

You can also check the Toptal resource pages for additional information on common CSS mistakes, a CSS hiring guide, CSS interview questions and CSS tips and best practices.

 

Click Here To Download CSS Cheat Sheet

Click Here To Check Complete article 

enable gZip compression

 

# force deflate for mangled headers
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/

SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding “gzip,deflate” env=HAVE_Accept-Encoding

 

# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:

FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype

Header only retrieval in php via curl

class URIInfo
{
public $info;
public $header;
private $url;


public function __construct($url)
{
$this->url = $url;
$this->setData();
}

public function setData()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_FILETIME, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$this->header = curl_exec($curl);
$this->info = curl_getinfo($curl);
curl_close($curl);
}


public function getFiletime()
{
return $this->info['filetime'];
}


// Other functions can be added to retrieve other information.
}


$uri_info = new URIInfo('http://vsjodha.com/');
$filetime = $uri_info->getFiletime();
if ($filetime != -1) {
echo date('Y-m-d H:i:s', $filetime);
} else {
echo 'filetime not available';
}

Posts Where Filter

add_filter( 'posts_where' , 'posts_where' );
function posts_where( $where ) {


if(!is_admin()){
global $wpdb;


if (isset($_GET['filter_state'])){
$filter_state = intval( $_GET['filter_state'] );
$where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id=$filter_state )";
}
if (isset( $_GET['filter_proff'])){
$childs = @implode(',',getChildCategories(intval($_GET['filter_proff'])));
$where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN($childs))";
}


if (isset( $_GET['filter_type'])){
$where .= " AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN(".$_GET['filter_type']."))";


}

}

return $where;
}

 

Update term count by SQL

update WordPress taxonomies(categories/tags)’ count field after bulk import/delete


UPDATE wp_term_taxonomy SET count = (
SELECT COUNT(*) FROM wp_term_relationships rel
LEFT JOIN wp_posts po ON (po.ID = rel.object_id)
WHERE
rel.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
AND
wp_term_taxonomy.taxonomy NOT IN ('link_category')
AND
po.post_status IN ('publish', 'future')
)

v3

Delete All Existing WordPress Transients in MySQL Database

DELETE FROM `wp_options` WHERE `option_name` LIKE ('_transient_%');
DELETE FROM `wp_options` WHERE `option_name` LIKE ('_site_transient_%');

Remember to use the correct table prefix. In the above example, the default table prefix has been used.

Ias infinite scroll

var ias = jQuery.ias({
container : ‘.myProjectBox’,
item: ‘.myProject’,
pagination: ‘div#MyProjectsPagination’,
next: ‘div#MyProjectsPagination a.next’, //’ul.page-numbers li a:first’
loader: ‘<img src=”http://www.hjcloseouts.com/wp-content/themes/WP-template-ydg/images/ajax-loader.gif”/>’
});

ias.extension(new IASTriggerExtension({html:'<div>LOAD MORE</div>’}));

ias.callback jquery-ias.min history ias.trigger noneleft paging spinner