Last active
August 29, 2015 14:22
-
-
Save rlynjb/c977f0187d1ffb6daa31 to your computer and use it in GitHub Desktop.
wp custom post type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates Job Positions Custom Post Type | |
function job_positions_init() { | |
$args = array( | |
'label' => 'Job Positions', | |
'public' => true, | |
'show_ui' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'rewrite' => array('slug' => 'job-positions'), | |
'query_var' => true, | |
'menu_icon' => 'dashicons-nametag', | |
'supports' => array( | |
'title', | |
'editor', | |
'excerpt', | |
'trackbacks', | |
'custom-fields', | |
'comments', | |
'revisions', | |
'thumbnail', | |
'author', | |
'page-attributes',) | |
); | |
register_post_type( 'job-positions', $args ); | |
} | |
add_action( 'init', 'job_positions_init' ); | |
// Create Custom Category to categorize Job Positions by Company | |
function job_locations_taxonomy() { | |
register_taxonomy( | |
'job_locations', | |
'job-positions', | |
array( | |
'hierarchical' => true, | |
'label' => 'Job Location List', | |
'query_var' => true, | |
'rewrite' => array( | |
'slug' => 'job-location', | |
'with_front' => false | |
) | |
) | |
); | |
} | |
add_action( 'init', 'job_locations_taxonomy'); | |
// Create Shortcode for Job Positions to display on Divi | |
function job_positions_available_display() { | |
$the_query = new WP_Query( array('post_type' => 'job-positions') ); | |
// The Loop | |
if ( $the_query->have_posts() ) { | |
$jobval = '<ul>'; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
// get and display job title, description, and custom fields | |
$jobval .= '<li>'; | |
$jobval .= '<h2>' . get_the_title() . '</h2>'; | |
$jobval .= '<p>' . get_the_content() . '</p>'; | |
$jobval .= 'Job Role: ' . get_post_meta(get_the_ID(), 'Job Role', true) . '<br>'; | |
$jobval .= 'Experience: ' . get_post_meta(get_the_ID(), 'Experience', true) . '<br>'; | |
$jobval .= 'Education: ' . get_post_meta(get_the_ID(), 'Education', true); | |
$jobval .= '</li>'; | |
} | |
return $jobval .= '</ul>'; | |
} else { | |
return 'Sorry, no available jobs at the moment.'; | |
} | |
wp_reset_postdata(); | |
} | |
add_shortcode( 'job_positions_available', 'job_positions_available_display' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment