Skip to content

Instantly share code, notes, and snippets.

View web-hat's full-sized avatar

WebHat web-hat

View GitHub Profile
@web-hat
web-hat / register_post_type.php
Created March 22, 2017 18:01
Add ‘/blog/’ Prefix in Blog Posts
<?php
$labels = [
"name" => __('Services', 'text-domain'),
//...
//...
];
$args = [
"label" => __('Services', 'text-domain'),
"labels" => $labels,
@web-hat
web-hat / whpp_track_post_views.php
Last active September 3, 2018 20:32
Display Popular Posts by Views in WordPress without a Plugin
<?php
function whpp_track_post_views($post_id) {
if (!is_single())
return;
if (empty($post_id)) {
global $post;
$post_id = $post->ID;
}
whpp_set_post_views($post_id);
@web-hat
web-hat / track_post_views_usage.php
Created March 22, 2017 18:07
Display Popular Posts by Views in WordPress without a Plugin
<?php
$args = [
//...
'meta_key' => 'whpp_track_post_views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
//...
];
$query = new WP_Query($args);
@web-hat
web-hat / product-category-custom-form.php
Last active March 27, 2017 18:10
WooCommerce Product Category custom field
<?php
add_action('product_cat_add_form_fields', 'wh_taxonomy_add_new_meta_field', 10, 1);
add_action('product_cat_edit_form_fields', 'wh_taxonomy_edit_meta_field', 10, 1);
//Product Cat Create page
function wh_taxonomy_add_new_meta_field() {
?>
<div class="form-field">
<label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label>
<input type="text" name="wh_meta_title" id="wh_meta_title">
<p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p>
@web-hat
web-hat / custom-field-save.php
Last active March 27, 2017 18:11
WooCommerce Product Category custom field
<?php
add_action('edited_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
add_action('create_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
// Save extra taxonomy fields callback function.
function wh_save_taxonomy_custom_meta($term_id) {
$wh_meta_title = filter_input(INPUT_POST, 'wh_meta_title');
$wh_meta_desc = filter_input(INPUT_POST, 'wh_meta_desc');
@web-hat
web-hat / field_usage.php
Created March 27, 2017 18:12
WooCommerce Product Category custom field
<?php
$productCatMetaTitle = get_term_meta($term_id, 'wh_meta_title', true);
$productCatMetaDesc = get_term_meta($term_id, 'wh_meta_desc', true);
@web-hat
web-hat / BlogPost.php
Created March 27, 2017 18:17
Accessing WordPress Post through Laravel
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BlogPost extends Model {
protected $connection = 'wordpress_db_connection';
protected $table = 'posts';
@web-hat
web-hat / BlogPostmeta.php
Created March 27, 2017 18:20
Accessing WordPress Post through Laravel
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BlogPostmeta extends Model {
protected $connection = 'wordpress_db_connection';
protected $table = 'postmeta';
@web-hat
web-hat / database_backup.sh
Last active March 27, 2017 18:27
Shell Script To Backup MySQL Database
#!/bin/sh
# Step 1: set up all the variables
###Set the file path where you want to store the backup file and set the name of the file.
FILE=/path/to/your/backup_dir/my_db_file.sql.$(date +'%Y%m%d')
###Database Details:
DBSERVER=db_host
DATABASE=db_name
USER=db_user
PASS=db_password
@web-hat
web-hat / laravel-config-database.php
Last active March 30, 2017 05:05
Change Default Database connection Dynamically.
<?php
return [
//...
//...
'default' => 'mysql_primary',
'connections' => [
//..
//Our Default Database Connection
'mysql_primary' => [