Skip to content

Instantly share code, notes, and snippets.

View tripflex's full-sized avatar
🦋
in the zone

Myles tripflex

🦋
in the zone
View GitHub Profile
@tripflex
tripflex / term-multiselect-field.php
Created February 4, 2016 03:07
How to set max selections for different term-multiselect fields (required template override)
<?php
// You need to use this file as a template override for this to work,
// for more details please see the wpjobmanager.com documentation:
// https://wpjobmanager.com/document/template-overrides/
// Get selected value
if ( isset( $field['value'] ) ) {
$selected = $field['value'];
} elseif ( ! empty( $field['default'] ) && is_int( $field['default'] ) ) {
$selected = $field['default'];
@tripflex
tripflex / multiselect-field.php
Last active March 9, 2016 18:50
Multiselect field editor template with Chosen support
<?php wp_enqueue_script( 'wp-job-manager-multiselect' ); ?>
<select multiple="multiple" name="<?php echo esc_attr( isset($field['name']) ? $field['name'] : $key ); ?>[]" id="<?php echo esc_attr( $key ); ?>" class="job-manager-multiselect" <?php if( ! empty($field['required']) ) echo 'required'; ?> data-no_results_text="<?php _e( 'No results match' ); ?>" data-multiple_text="<?php _e( 'Select Some Options' ); ?>">
<?php
$no_values = isset( $field['value'] ) ? false : true;
foreach ( $field['options'] as $key => $value ) :
$key = str_replace( '*', '', $key, $replace_default );
$key = str_replace( '~', '', $key, $replace_disabled );
$field_value = isset( $field['value'] ) ? $field['value'] : array();
if( $no_values && $replace_default > 0) $field[ 'value' ][ ] = $key;
@tripflex
tripflex / functions.php
Created February 15, 2016 20:55
How to output File Upload Field Type as link with filename as label/caption through custom ShortCode
<?php
add_shortcode('listing_custom_file_output', 'listing_custom_file_output_filename_link');
function listing_custom_file_output_filename_link( $atts, $content = ''){
// !! WARNING !!
// When using the core WordPress `get_post_meta` you MUST prepend the meta key
// with an underscore. So if the meta key was listing_custom_file, below it
// needs to be _listing_custom_file
$file_paths = get_post_meta( get_the_ID(), "_listing_custom_file")
@tripflex
tripflex / functions.php
Created February 24, 2016 01:05
Output taxonomy as comma separated value (auto output, php, widget, shortcode) for WP Job Manager Field Editor
<?php
//
// CUSTOM FILTER TO ADD COMMA AFTER TAXONOMY OUTPUT FOR FIELD EDITOR
//
//
add_filter( 'field_editor_output_no_wrap_after', 'mysite_check_if_need_to_output_csv', 10, 6 );
function mysite_check_if_need_to_output_csv( $separator, $field_slug, $job_id, $field_values, $args, $single_value ){
@tripflex
tripflex / WordPress.xml
Created February 24, 2016 20:16 — forked from Rarst/WordPress.xml
WordPress Live Templates for PhpStorm
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="WordPress">
<template name="aa" value="add_action( '$hook$', '$callback$' );&#10;$END$" description="add_action" toReformat="false" toShortenFQNames="true">
<variable name="hook" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="callback" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
@tripflex
tripflex / functions.php
Created February 25, 2016 21:30
WP Job Manager Job List Custom Sort by Meta Field Value
<?php
// https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
function xyz_custom_orderby( $query_args ) {
// Use meta_value_num for numeric sorting (if issues with meta_value)
$query_args[ 'orderby' ] = 'meta_value';
$query_args[ 'order' ] = 'ASC';
return $query_args;
}
add_filter( 'job_manager_get_listings_args', 'xyz_custom_orderby', 99 );
@tripflex
tripflex / content-single-job_listing.php
Created March 9, 2016 18:28
Output standard text field with space or comma separated values with line break (or custom HTML) after each item
<?php
$field_values = get_custom_field( 'field_meta_key' );
if( ! empty( $field_values ) ){
// The default in code below is to output a line break HTML (<br />) after each item,
// if you want to use something else or different HTML, just replace <br /> below
@tripflex
tripflex / content-single-job_listing.php
Last active June 30, 2016 02:50
Foreach PHP loop to customize output of taxonomy or field that is saved as an array
<?php
$sh_indoor_outdoor = get_job_field( 'indoor_outdoor' );
if( is_array( $sh_indoor_outdoor ) && ! empty( $sh_indoor_outdoor ) ){
foreach( $sh_indoor_outdoor as $value ){
// Go to next item if $value is an empty string, 0, false, or empty array
if( empty( $value ) ) continue;
@tripflex
tripflex / functions.php
Last active April 29, 2025 14:57
How to add additional email addresses when email is sent to WordPress admin_email option value
<?php
/**
*
* WARNING: this only checks if the email is being sent to the same email as admin_email option.
* If for some reason another email is sent to that same email address, but it's not meant as an "admin email"
* this filter will still add those additional emails, just something to keep in mind.
*/
add_filter( 'wp_mail', 'my_custom_to_admin_emails' );
@tripflex
tripflex / content-single-job_listing-company.php
Last active April 26, 2016 21:57
Add additional social media links to Listable WordPress theme
<?php
/**
* Single view Company information box
*
* Hooked into single_job_listing_start priority 30
*
* @since 1.14.0
*/