Last active
November 26, 2018 21:27
-
-
Save richerimage/e49e2c5c400864ea085e2cba61e58dee to your computer and use it in GitHub Desktop.
cvl-facet-functions.php
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
<?php | |
add_filter( 'facetwp_query_args', function( $query_args, $class ) { | |
$parent = get_the_ID(); | |
if ( 'example' == $class->ajax_params['template'] ) { | |
$query_args['post_parent'] = $parent; | |
$query_args['post_type'] = 'job_application'; | |
$query_args['post_status'] = 'published'; | |
$query_args['posts_per_page'] = '10'; | |
} | |
return $query_args; | |
}, 10, 2 ); | |
// this what I have in the display tab of the 'example' template | |
// it's wrapped in <?php tags | |
require_once CVLP . 'cvl-facetwp/cvl-facetwp.php'; | |
echo test_before(); | |
while ( have_posts() ): the_post(); | |
echo test(); | |
endwhile; | |
echo test_after(); | |
/* end of display tab content | |
* | |
* for comlpleteness here's the entire content of the | |
* require_once CVLP . 'cvl-facetwp/cvl-facetwp.php file | |
* | |
* the 'facetwp_is_main_query' at the end is used on another | |
* (working) facet template at https://cvl.stemcell.zone/job-dashboard | |
* | |
*/ | |
function test() { | |
$id = get_the_ID(); | |
$name = get_the_title(); | |
$link = get_permalink( $id ); | |
// $terms = get_the_terms($id, 'cvl_app_status'); | |
// $status = $terms[0]->name; | |
$terms_array = get_the_terms($id, 'cvl_app_status'); | |
$terms = ''; | |
if (is_array($terms_array)) { | |
foreach($terms_array as $term) { | |
if (isset($term->name)) { | |
$terms .= $term->name; | |
} | |
} | |
} | |
$status = $terms; | |
$cv = get_post_meta( $id, '_attachment', true ); | |
$cv_dl = !empty($cv) ? '<a href="' . $cv[0] . '">Download CV</a>' : 'No CV to Download'; | |
$email = !empty(get_post_meta( $id, '_candidate_email', true )) ? '<a href="mailto:' . get_post_meta( $id, '_candidate_email', true ) . '">Email Applicant</a>' : 'No email provided'; | |
$ref = !empty(get_post_meta( $id, 'applicant_referrer_company_logo', true)) ? get_post_meta( $id, 'applicant_referrer_company_logo', true) : 'No Referrer ID\'d'; | |
$pre_note = get_post_meta( $id, 'cvl_app_note', true ); | |
$update_name = 'postContent_' . $id; | |
$submit_name = 'submitted_' . $id; | |
$current_user = wp_get_current_user(); | |
$user_name = esc_html($current_user->display_name); | |
if ( isset( $_POST[$submit_name] )) { | |
$time = '<div class="update-note-entry"><p><strong>' . $user_name . ' > ' . date('m/d/y h:i:s a', time()) . ':</strong></p>'; | |
$update = $_POST[$update_name] . '</div>'; | |
$updated_post = $time . $update . ' ' . $pre_note; | |
update_post_meta( $id, 'cvl_app_note', wpautop($updated_post) ); | |
echo '<p>Updated Successfully! 👍🏼</p>'; | |
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.the_permalink().'">'; | |
exit; | |
} | |
$notes = "<h3>Notes</h3>" . | |
"<div class=\"update-notes col-12\">". | |
$pre_note . | |
"</div>". | |
"<h4>Update Note</h4>". | |
"<form action=\"\" id=\"cvl_update_app_meta\" class=\"cvl-update-app-meta\" method=\"POST\">". | |
"<textarea name=\"{$update_name}\" id=\"{$update_name}\" rows=\"3\"></textarea>". | |
"<input type=\"hidden\" name=\"{$submit_name}\" id=\"{$submit_name}\" value=\"true\" />". | |
"<button class=\"update-note\" type=\"submit\">Update</button>". | |
"</form>"; | |
$data_rows = "<div id=\"app_id_{$id}\" class=\"table-row app-id-{$id}\">". | |
"<span class=\"cvl-app-options\"><a href=\"$link\">View</a></span>". | |
"<span class=\"cvl-app-details\">{$name} <small>(ID: {$id})</small></span>". | |
"<span class=\"cvl-app-cv\">$cv_dl</span>". | |
"<span class=\"cvl-app-email\">{$email}</span>". | |
"<span class=\"cvl-app-ref\">{$ref}</span>". | |
"<span class=\"cvl-app-status\">{$status}</span>". | |
"<span class=\"cvl-app-notes\">". $notes . "</span>". | |
"</div>"; | |
$output = $data_rows; | |
return $output; | |
} | |
function test_before() { | |
$output = "<h4>Applications Received</h4>". | |
"<div class=\"cvl-table cvl-job-app-table\">". | |
"<header class=\"table-row table-header\">". | |
"<span class=\"cvl-app-options\">Options</span>". | |
"<span class=\"cvl-app-details\">Details</span>". | |
"<span class=\"cvl-app-cv\">Download CV</span>". | |
"<span class=\"cvl-app-email\">Email</span>". | |
"<span class=\"cvl-app-ref\">Referred By</span>". | |
"<span class=\"cvl-app-status\">Status</span>". | |
"</header>". | |
"<div class=\"table-results\">"; | |
return $output; | |
} | |
function test_after() { | |
$output = "</div> <!-- .table-results -->". | |
"<footer>" . facetwp_display( 'pager' ) . "</footer>". | |
"</div> <!-- .cvl-job-app-table -->"; | |
return $output; | |
} | |
add_filter( 'facetwp_query_args', function( $query_args, $class ) { | |
$parent = get_the_ID(); | |
if ( 'example' == $class->ajax_params['template'] ) { | |
$query_args['post_parent'] = $parent; | |
$query_args['post_type'] = 'job_application'; | |
$query_args['post_status'] = 'published'; | |
$query_args['posts_per_page'] = '10'; | |
} | |
return $query_args; | |
}, 10, 2 ); | |
// https://facetwp.com/documentation/facetwp_is_main_query/ | |
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) { | |
if ( '' !== $query->get( 'facetwp' ) ) { | |
$is_main_query = (bool) $query->get( 'facetwp' ); | |
} | |
return $is_main_query; | |
}, 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment