Skip to content

Instantly share code, notes, and snippets.

@jeffward3283
jeffward3283 / wpdb-column-examples.php
Last active December 25, 2023 20:19
WordPress Database Examples
<?php
////////////////////////
# COLUMN EXAMPLES
////////////////////////
////////////////////////
# Add Column (after)
////////////////////////
global $wpdb;
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<h1>Here is my map of a particular Bay Area company</h1>
<div id="my-map"></div>
<script type="text/javascript">
jQuery(document).ready(function($){
// Grab the target map
var $map = $('#my-map');
<?php
/////////////////////////////////////////////////////////////////
# Create a Simple JSON Based Download Counter with WordPress
/////////////////////////////////////////////////////////////////
// Extending from:
// http://www.kavoir.com/2010/05/simplest-php-hit-counter-or-download-counter-count-the-number-of-times-of-access-visits-or-downloads.html
function download_count_actions($id = null, $step = 'get', $file = null){
# Note for newbies: Because we know what we're doing, we will prepend the file functions with the at sign (@) to supress known PHP errors
<?php
///////////////////////////////////////
# WordPress Remote Request (Retreive)
///////////////////////////////////////
$url = 'https://external-site.com/api/?json=1';
// $response = file_get_contents($url); // old method
$request = wp_remote_get( $token_url, array( 'sslverify' => false, 'timeout' => 120 ) );
$response = wp_remote_retrieve_body( $request );
echo '<pre>';
<?php
///////////////////////////////////
# Enqueue Human Comment Script
///////////////////////////////////
add_action('wp_enqueue_scripts', 'add_human_comment_script'); // Add Theme Stylesheet
function add_human_comment_script(){
wp_register_script('human_comments', admin_url() . 'admin-ajax.php?action=human_comments_script', array('jquery'), '1.0', true);
wp_enqueue_script('human_comments');
}
@jeffward3283
jeffward3283 / example-wp-post-metabox.php
Last active March 12, 2020 14:35
example-wp-post-metabox.php
<?php
///////////////////////////////
# COMPLETE METABOX EXAMPLE
///////////////////////////////
///////////////////////////////
# I. ADD METABOX
<?php
/////////////////////////////
# Register Post Type
/////////////////////////////
add_action('init', 'register_post_type_review');
function register_post_type_review(){
# NOTE: to enable comments for your custom post type, you must set the option 'default_comment_status' to true: update_option('default_comment_status', true);
// or goto: WP ADMIN => SETTINGS => DISCUSSION => check the "Allow people to post comments on new articles"
<?php
//////////////////////////
# Set Emails as HTML
//////////////////////////
if(!function_exists('set_html_content_type')){
function set_html_content_type() {
return 'text/html';
}
}
<?php
////////////////////////////
# WP AJAX EXAMPLE
////////////////////////////
/////////////////////////
# Enqueue Script
/////////////////////////