This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Show Posts based on a keyword search | |
| $query = new WP_Query( array( 's' => 'keyword' ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $id = get_cat_id('Category-Sample'); | |
| $q = "cat=-" . $id; | |
| query_posts($q); | |
| if (have_posts()) : while (have_posts()) : the_post(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ) ) { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // In Between PHP | |
| <?php if(condition){ ?> | |
| HTML | |
| <?php } ?> | |
| // In An PHP | |
| if(condition){ | |
| echo "HTML"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ) { | |
| } |