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 / wp-dropdown-posts.php
Last active January 28, 2021 19:05
WordPress wp_dropdown_posts() function. Based off wp_dropdown_users() and wp_dropdown_pages() (EDIT MOVED TO REPO: https://github.com/tripflex/wp_dropdown_posts )
<?php
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;
if( ! function_exists( 'wp_dropdown_posts' ) ) {
/**
* Create dropdown HTML content of posts
*
@tripflex
tripflex / functions.php
Last active March 31, 2016 16:13
Update WP Job Manager Field on Save or Update (For saving value when used with Action Hook field type)
<?php
/*
* Save/Update Listing when Save/Update from Frontend
*/
add_action( 'job_manager_update_job_data', 'smp920_update_my_fields', 100, 2 );
function smp920_update_my_fields( $job_id, $values ){
// Check for value in $_POST, then set var with sanitized value, CHANGE my_input_name to the NAME used in the input HTML element
$my_input_name = isset( $_POST['my_input_name'] ) ? sanitize_text_field( $_POST['my_input_name'] ) : false;
@tripflex
tripflex / functions.php
Last active April 5, 2016 22:06
How to set Job Category from another custom Taxonomy when using WP Job Manager Field Editor
<?php
add_action( 'job_manager_field_editor_save_custom_field_end', 'update_my_custom_tax_field_editor_fields', 10, 5 );
/**
* Update Listing job_category from job_category_dentist taxonomies
*
* REQUIRES: WP Job Manager Field Editor 1.4.2+
*
* This can be useful if you want to set the Job Category but for some reason have that field hidden,
* disabled, or set to not show for a specific package, but still want the category set (or maybe you want
@tripflex
tripflex / functions.php
Last active September 12, 2016 21:45
Change the default WP Job Manager file upload directory
add_filter( 'job_manager_upload_dir', 'my_custom_job_manager_upload_dir' );
function my_custom_job_manager_upload_dir( $job_manager_uploading_file ) {
// This is the default below
// $dir = 'job-manager-uploads/' . $job_manager_uploading_file;
// This is using a custom directory, make sure to add $job_manager_uploading_file to the end of the string
$dir = 'custom_jm_uploads/' . $job_manager_uploading_file;
@tripflex
tripflex / functions.php
Created April 8, 2016 00:06
Set field configuration through PHP for WP Job Manager with WP Job Manager Field Editor 1.4.2+ (example is for setting options)
<?php
/**
* Filter for fields before filtering based on $filter value
*
* Filter syntax is `job_manager_field_editor_get_fields_pre_filter_{$field_group}` ... replace {$field_group} with field group
*
* Job Fields: job_manager_field_editor_get_fields_pre_filter_job
* Company Fields: job_manager_field_editor_get_fields_pre_filter_company
* Resume Fields: job_manager_field_editor_get_fields_pre_filter_resume_fields
*
@tripflex
tripflex / functions.php
Created May 12, 2016 22:22
Add a custom field to the WP Job Manager Job Listings Admin List Table (unsortable)
<?php
//ONLY ADD COLUMN AND CONTENT TO CUSTOM JOB LISTINGS POSTS
add_filter('manage_job_listing_posts_columns', 'xyz123_my_custom_job_listing_columns');
add_action('manage_job_listing_posts_custom_column', 'xyz123_my_custom_job_listing_column_value', 10, 2);
// ADD COLUMN TO LIST TABLE
function xyz123_my_custom_job_listing_columns($defaults) {
$defaults['job_metakey'] = 'LabelHere';
return $defaults;
@tripflex
tripflex / functions.php
Created May 16, 2016 23:56
array_insert function, insert array into another array before/after a certain key
<?php
if( ! function_exists( 'array_insert' ) ) {
/**
* Insert an array into another array before/after a certain key
*
* @param array $array The initial array
* @param array $pairs The array to insert
* @param string $key The certain key
* @param string $position Wether to insert the array before or after the key
@tripflex
tripflex / functions.php
Created June 13, 2016 14:35
Prepend a custom value on a URL for specific WP Job Manager fields (only works with single values, not array values)
<?php
add_filter( 'get_post_metadata', 'my_custom_url_prepend_value', 99999, 4 );
/**
* Get Meta Filter
*
* Filter the get_metadata function to return specific value we
* customize.
*
@tripflex
tripflex / functions.php
Created June 16, 2016 15:23
Set a field as Read Only using jQuery
<?php
add_action( 'submit_job_form_start', 'my_custom_jquery_set_field_readonly' );
function my_custom_jquery_set_field_readonly(){
/**
* Replace FIELD_META_KEY with the meta key of the field you want to set as readonly.
* If you want to set it as disabled instead, just change 'readonly' to 'disabled'
*/
echo "<script>jQuery(function($){ $('#FIELD_META_KEY').prop('readonly', true); });</script>";
@tripflex
tripflex / functions.php
Last active March 19, 2025 11:59
WordPress Remove Filter (remove_filter converted to remove_class_filter) to remove Filter/Action without Class Object access. Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
<?php
/**
* Make sure the function does not exist before defining it
*/
if( ! function_exists( 'remove_class_filter' ) ){
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback