Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / wp-custom-content-folder.php
Created November 26, 2015 19:43
Custom Content Directory for WordPress
<?php
* Custom Content Directory
*/
define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER[ 'HTTP_HOST' ] . '/content' );
?>
@wpmark
wpmark / wp-query-orderby-muliple-meta-keys.php
Created November 18, 2015 12:48
WP_Query Ordered By Multiple Meta Keys
<?php
/* build a new wp_query */
$classes = new WP_Query(
array(
'post_type' => 'wpmark_class_time', // post type to query
'posts_per_page' => -1, // get all the posts not limited
'meta_query' => array(
'relation' => 'AND',
'day' => array( // give the first meta key array an array key
'key' => '_wpmark_day',
@wpmark
wpmark / wp-ajax-search-functions-hooked.php
Last active November 16, 2019 14:34
AJAX Search Function for Post Titles
<?php
function myplugin_ajax_job_search() {
/* get the search terms entered into the search box */
$search = sanitize_text_field( $_POST[ 'search' ] );
/* run a new query including the search string */
$q = new WP_Query(
array(
'post_type' => job_post_type_name,
@wpmark
wpmark / wp-enqueue-localised-script.php
Created October 21, 2015 18:48
Enqueuing a localised script in WordPress
<?php
function myplugin_enqueue_scripts() {
/* hand the js for deleting uploads by ajax */
wp_enqueue_script(
'myplugin-utilities-ajax',
plugins_url( '/assets/js/nameofjsfile.js', __FILE__ ),
array( 'jquery' ),
'1.0.0',
true
@wpmark
wpmark / ajax-search.js
Created October 21, 2015 18:45
Code for Running an AJAX Search in WordPress
( function( $ ) {
// hooks everything into document ready
$(document).ready( function() {
// create a function to actually fire the search
function dosearch(t) {
// do the ajax request for job search
$.ajax({
@wpmark
wpmark / using-media-handle-sideload.php
Created July 10, 2015 10:32
Using Media Handle Sideload
<?php
/* set the url of the file to sideload - probably be from $_POST or something */
$url = 'http://domain.com/image.jpg';
/**
* donwload the url into wordpress
* saved temporarly for now
*/
$tmp = download_url( $url );
@wpmark
wpmark / admin-mu-link-orig-domain.php
Created June 25, 2015 13:02
Admin Links in Multisite Always go to Original Domain
@wpmark
wpmark / cpt-archive-show-all-posts.php
Last active June 8, 2018 06:13
Pre Get Posts to Show All Posts for Custom Post Type Archive
<?php
function wpmark_alter_team_archive_template_query( $query ) {
/* only proceed on the front end */
if( is_admin() ) {
return;
}
/* only on the person post archive for the main query */
if ( $query->is_post_type_archive( 'wpmark_person' ) && $query->is_main_query() ) {
@wpmark
wpmark / cpt-archive-orderby-term.php
Last active August 29, 2015 14:23
Custom Post Type Archive Posts Ordered by Term
<?php
/* get our array of post ids in term order */
$people = wpmark_get_posts_in_terms_array(
array(
'orderby' => 'id',
'taxonomy' => 'sdance_person_type',
'posts' => $wp_query->posts
)
);
@wpmark
wpmark / register-shortcode-with-ui.php
Created May 6, 2015 18:05
Register Shortcode with Shortcode UI
<?php
/**
* function wpmark_register_before_after_shortcake()
*/
function wpmark_register_before_after_shortcake() {
shortcode_ui_register_for_shortcode(
'before_after_image', // name of shortcode ui