Skip to content

Instantly share code, notes, and snippets.

View fahaadsheikh's full-sized avatar

Fahad Sheikh fahaadsheikh

  • Karachi Pakistan
View GitHub Profile
@fahaadsheikh
fahaadsheikh / dynamic_rewrite_rules
Created August 18, 2018 21:54
Add rewrite rules for a selected template
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class RegisterLocationRewriteRule
{
/**
* Start up
@fahaadsheikh
fahaadsheikh / combine_and_sort_cpt_by_date
Last active March 19, 2018 18:32
Used to combine two custom post types for their archive pages and sort them by date meta value
<?php
function combine_and_sort_cpt_by_date( $query ) {
$post_types = array(
'post_type_one',
'post_type_two'
)
if ( $query->is_post_type_archive( $post_types ) ) {
$query->set( 'post_type', $post_types );
$query->set( 'orderby', 'meta_value' );
@fahaadsheikh
fahaadsheikh / Register WordPress Widgets
Created March 17, 2018 18:23
Use to create a widget in OOP Style
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class RegisterWidgets
{
/**
@fahaadsheikh
fahaadsheikh / metaboxes.php
Created December 15, 2017 07:35
Add Metaboxes to Wordpress Post Types
<?php
/**
* Add Metaboxes to Wordpress Post Types
*/
class Add_Metabox {
function __construct() {
add_action( 'add_meta_boxes', array( $this , 'register_metabox') );