Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
@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
@wpmark
wpmark / before-after-shortcode-jquery
Created May 6, 2015 17:59
Before and After Shortcode jQuery
/**
* trigger the before and after images
*/
var beforeafter = function() {
/* get the preceeding element before the toggle button - hides all the after images */
$( '.before-after-toggle' ).prev().hide();
/* when the element with 'before-after-toggle' class is clicked */
$( '.before-after-toggle' ).click(function() {
@wpmark
wpmark / before-after-shortcode.php
Created May 6, 2015 17:53
Before and After Image Shortcode
<?php
/**
* function wpmark_add_before_after_shortcode()
* adds the shortcode to output the before and after image
*/
function wpmark_add_before_after_shortcode( $attr ) {
$attr = wp_parse_args(
$attr,
array(