Home › Toolset Professional Support › [Resolved] help with new relationships
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
Tagged: Post-relationship
This topic contains 1 reply, has 2 voices.
Last updated by Luo Yang 6 years, 6 months ago.
Assisted by: Luo Yang.
I have some php in my Divi child theme functions.php that has been added over the last couple of years with help from Toolset support.
I now need some help know whether or not this code should be updated for the new relationship situation - and if so, how to do it.
Here is a copy of my current functions.php file:
<?php
update_option('siteurl','hidden link');
update_option('home','hidden link');
/*send bcc of customers completed email order for woo commerce*/
add_filter( 'woocommerce_email_headers', 'mycustom_headers_filter_function', 10, 2);
function mycustom_headers_filter_function( $headers, $object ) {
if ($object == 'customer_completed_order') {
$headers .= 'BCC: NMI Admin <admin@nmi.org>' . "\r\n";
}
return $headers;
}
/* Disable Related products on single product pages */
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'Divi', get_template_directory_uri() . '/style.css' );
}
//allow conference registration to force new posts to belong to the 2016 conference parent
add_shortcode('my_parent','my_parent');
function my_parent($atts, $content)
{
global $post;
return $post->ID;
}
//make all search-submissions automatically the Search Submission Category
add_action('cred_save_data_14234', 'save_data_for_form_with_id_14234',10,2);
function save_data_for_form_with_id_14234($post_id, $form_data)
{
// your code goes here for CRED form 1444
if(!has_term('','musical-category',$post_id))
{
$category_ids = array(479); // replace your category ID
wp_set_object_terms( $post_id, $category_ids, 'musical-category');
}
wp_update_post( $my_post );
}
// restrict number of characters for view output to 1500 characters
add_shortcode('trim', 'trim_shortcode');
function trim_shortcode($atts, $content = '') {
$content = do_shortcode($content);
if (strlen($content) > 2000) {
$content = substr($content, 0, 2000);
}
return $content;
}
// shortcode to return info for specific categories in VIEWS
add_shortcode("get-cats", "get_cats");
function get_cats($atts) {
$id = $atts["post_id"];
$cat = $atts["cat"];
$taxonomy_name = $atts["taxonomy"];
$termId = 0;
if($cat == "length") {$termId = 78;}
if($cat == "award") {$termId = 92;}
if($cat == "adaptation") {$termId = 221;}
if($cat == "pd-genre") {$termId = 198;}
if($cat == "pd-original") {$termId = 213;}
$catlist = array();
$termchildren = get_term_children( $termId, $taxonomy_name );
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
if(has_term( $term->slug, $taxonomy_name, $id )) {
$catlist[] = $term->name;
}
}
$cats = implode( ", ", $catlist );
return $cats;
}
// to remove edit links in Types views
add_filter('wpv_edit_view_link', 'prefix_remove_edit_links');
function prefix_remove_edit_links( $link ) {
return '';
}
// to allow export of full calendar
add_action( 'pre_get_posts', 'full_ical_export' );
function full_ical_export( WP_Query $query ) {
if ( ! isset( $_GET['ical'] ) || ! isset( $_GET['full-export'] ) ) return;
if ( ! isset( $query->tribe_is_event_query ) || ! $query->tribe_is_event_query ) return;
$query->set( 'eventDisplay', 'custom' );
$query->set( 'start_date', '1000-01-01' );
$query->set( 'end_date', '3000-01-01' );
$query->set( 'posts_per_page', '-1' );
}
// to allow for adding up totals in fields
global $total;
add_shortcode('add-to-total', 'add_total_shortcode');
function add_total_shortcode($atts, $content = '') {
global $total;
$string = str_replace('$', '', $string);
$total += wpv_do_shortcode($content);
}
add_shortcode('show-total', 'show_total_shortcode');
function show_total_shortcode() {
global $total;
$totalNew = $total;
$total = 0;
return $totalNew;
}
global $total2;
add_shortcode('add-to-total2', 'add_total2_shortcode');
function add_total2_shortcode($atts, $content = '') {
global $total2;
$string = str_replace('$', '', $string);
$total2 += wpv_do_shortcode($content);
}
add_shortcode('show-total2', 'show_total2_shortcode');
function show_total2_shortcode() {
global $total2;
$totalNew2 = $total2;
$total2 = 0;
return $totalNew2;
}
global $total3;
add_shortcode('add-to-total3', 'add_total3_shortcode');
function add_total3_shortcode($atts, $content = '') {
global $total3;
$string = str_replace('$', '', $string);
$total3 += wpv_do_shortcode($content);
}
add_shortcode('show-total3', 'show_total3_shortcode');
function show_total3_shortcode() {
global $total3;
$totalNew3 = $total3;
$total3 = 0;
return $totalNew3;
}
global $johnyestotal;
$johnyestotal = 0;
add_shortcode('add-to-johnyestotal', 'add_johnyestotal_shortcode');
function add_johnyestotal_shortcode($atts, $content = '') {
global $johnyestotal;
$johnyestotal += do_shortcode($content);
}
add_shortcode('show-johnyestotal', 'show_johnyestotal_shortcode');
function show_johnyestotal_shortcode() {
global $johnyestotal;
return $johnyestotal;
}
global $johnnototal;
$johnnototal = 0;
add_shortcode('add-to-johnnototal', 'add_johnnototal_shortcode');
function add_johnnototal_shortcode($atts, $content = '') {
global $johnnototal;
$johnnototal += do_shortcode($content);
}
add_shortcode('show-johnnototal', 'show_johnnototal_shortcode');
function show_johnnototal_shortcode() {
global $johnnototal;
return $johnnototal;
}
// to allow math calculations on multiple fields
add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts) {
return wpv_condition($atts);
}
// to allow math calculations on multiple shortcodes
add_shortcode('wpv-shortcodecalculate', 'calculate_shortcode2');
function calculate_shortcode2($atts,$content=null) {
$content = wpv_do_shortcode($content);
$content = eval("return $content;");
return round($content);
}
// to allow Views to display The Events Calendar type custom fields that can't be accessed the usual way
function postcf_func($atts){
$field = $atts["field"];
$post_id = $atts["post_id"];
return get_post_meta($post_id, $field, true);
}
add_shortcode("postcf", "postcf_func");
// To check union
function check_union_member_shortcode($atts,$content){
$x = do_shortcode($content);
$x = explode(",",$x);
$cnt = count(array_intersect($x, array('AEA','SAG-AFTRA','AGVA')));
if($cnt > 0){
return '<b>*</b>';
}
}
add_shortcode("check_for_union", "check_union_member_shortcode");
// to allow a particular User View to sort by lastname instead of ID
add_filter('wpv_filter_user_query', 'sort_users_by_lastname', 99, 3);
function sort_users_by_lastname( $query_args, $view_settings, $view_id ) {
if($view_id == 14207) { // change 123 with correct ID of your view
$query_args['meta_key'] = 'last_name';
$query_args['orderby'] = 'meta_value';
$query_args['order'] = 'ASC'; // valid values ASC or DESC
}
return $query_args;
}
// to re-direct Woo Commerce and Cred Commerce buyers to a customized thank you page instead of the orders-received endpoint
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( 'hidden link' );
exit;
}
}
//assign post author based on url parameter author-filter
add_action('cred_save_data', 'my_other_save_data_action',10,2);
function my_other_save_data_action($post_id, $form_data)
{
// if a specific form
if (in_array($form_data['id'], array(16701, 16711, 17309, 18557, 34386 )))
{
if (isset($_POST['author-filter']))
{
$args = array(
'ID' => $post_id,
'post_author' => $_POST['author-filter'],
);
$res = wp_update_post( $args, true );
}
}
}
//assign post author based on url parameter users-filter
add_action('cred_save_data', 'my_other_save_data2_action',10,2);
function my_other_save_data2_action($post_id, $form_data)
{
// if a specific form
if (in_array($form_data['id'], array(14577 )))
{
if (isset($_POST['users-filter']))
{
$args = array(
'ID' => $post_id,
'post_author' => $_POST['users-filter'],
);
$res = wp_update_post( $args, true );
}
}
}
//next three are for the Volunteer Tasks - to change the value for the STATUS field
add_action('cred_save_data', 'my_volunteer_claimed_data_action',10,2);
function my_volunteer_claimed_data_action($post_id, $form_data)
{
if ($form_data['id']==19248)
{
$parent_post = get_post_meta($post_id, '_wpcf_belongs_volunteer-task_id', true);
$status = 'CLAIMED';
update_post_meta($parent_post, 'wpcf-volunteer-task-admin-status', $status);
$personal = 'CLAIMED';
update_post_meta($post_id, 'wpcf-volunteer-personal-status', $personal);
}
}
add_action('cred_save_data', 'my_volunteer_completed_data_action',10,2);
function my_volunteer_completed_data_action($post_id, $form_data)
{
if ($form_data['id']==19267)
{
$parent_post = get_post_meta($post_id, '_wpcf_belongs_volunteer-task_id', true);
$status = 'COMPLETED';
update_post_meta($parent_post, 'wpcf-volunteer-task-admin-status', $status);
}
}
add_action('cred_save_data', 'my_volunteer_cancelled_data_action',10,2);
function my_volunteer_cancelled_data_action($post_id, $form_data)
{
if ($form_data['id']==19496)
{
$parent_post = get_post_meta($post_id, '_wpcf_belongs_volunteer-task_id', true);
$status = 'AVAILABLE';
update_post_meta($parent_post, 'wpcf-volunteer-task-admin-status', $status);
$personal = 'CANCELLED';
update_post_meta($post_id, 'wpcf-volunteer-personal-status', $personal);
}
}
//on Events Manager Reservation Form - change "price" to "cost" and "spaces" to "tickets"
function my_custom_ticket_header($collumns){
$collumns = array( 'type' => __('Ticket Type','dbem'), 'price' => __('Ticket Price:','dbem'), 'spaces' => __('# of Tickets:','dbem'));
return $collumns;
}
add_filter('em_booking_form_tickets_cols','my_custom_ticket_header',1,1);
//reformat the Events Manager _event_start_date, , _event_end_date, _event_start_time, and _event_end_time fields
add_filter( 'wpv-post-field-_event_start_date', 'format_event_start_date', 20, 2 );
function format_event_start_date($field_value, $meta)
{
$formated_date = date("D, M j", strtotime($field_value));
return $formated_date;
}
add_filter( 'wpv-post-field-_event_end_date', 'format_event_end_date', 20, 2 );
function format_event_end_date($field_value, $meta)
{
$formated_date = date("D, M j", strtotime($field_value));
return $formated_date;
}add_filter( 'wpv-post-field-_event_start_time', 'format_event_start_time', 20, 2 );
function format_event_start_time($field_value, $meta)
{
$formated_time = date("g:i a", strtotime($field_value));
return $formated_time;
}
add_filter( 'wpv-post-field-_event_end_time', 'format_event_end_time', 20, 2 );
function format_event_end_time($field_value, $meta)
{
$formated_time = date("g:i a", strtotime($field_value));
return $formated_time;
}
//allows a specific View to filter the Events Manager START date field properly
add_filter('wpv_filter_custom_field_filter_processed_value', 'format_event_start_date_comparison', 10, 3);
function format_event_start_date_comparison($value, $key, $view_id)
{
if (in_array($view_id, array(15587, 15984, 16005, 16088, 16095, 16367, 16406, 16608, 16610, 16663, 16665, 16669, 16765, 16671, 16678, 16679, 17793, 18300, 18316, 18362, 18300, 18370, 18373, 18377, 18414, 18418, 18621, 18626, 19766, 29544, 29905, 30202, 30210, 30361, 31627, 31631, 31670, 31681, 31682, 33150, 33303, 33304, 39292, 39498, 45847, 45851, 48043, 50156, 51420, 52888, 53199, 53433, 53444, 53445, 53446, 54574, 53199, 56940)) && $key == '_event_start_date')
{
return date('Y-m-d', $value);
}
return $value;
}
//allows a specific View to filter the Events Manager END date field properly
add_filter('wpv_filter_custom_field_filter_processed_value', 'format_event_end_date_comparison', 10, 3);
function format_event_end_date_comparison($value, $key, $view_id)
{
if (in_array($view_id, array(15587, 15984, 16005, 16088, 16095, 16367, 16406, 16608, 16610, 16663, 16665, 16669, 16765, 16671, 16678, 16679, 17793, 18300, 18316, 18362, 18300, 18370, 18373, 18377, 18414, 18418, 18621, 18626, 19766, 29544, 29905, 30202, 30210, 30361, 31627, 31631, 31670, 31681, 31682, 33150, 33303, 33304, 39292, 39498, 45847, 45851, 48043, 50156, 51420, 52888, 53199, 53433, 53444, 53445, 53446, 54574, 53199, 56940)) && $key == '_event_end_date')
{
return date('Y-m-d', $value);
}
return $value;
}
// ORDERBY date and then by time - for Events Manager - if View is in array - currently Events by Category and Rental View
add_filter( 'wpv_filter_query_post_process', 'sort_query_func', 10, 3 );
function sort_query_func( $query, $view_settings, $view_id ) {
if (!empty( $query->posts )
&& in_array($view_id, array(15587, 15984, 16005, 16088, 16095, 16367, 16406, 16608, 16610, 16663, 16665, 16669, 16765, 16671, 16678, 16679, 17793, 18300, 18362, 18300, 18370, 18373, 18377, 18414, 18418, 18621, 18626, 19766, 29544, 29905, 30202, 30210, 30361, 31627, 31631, 31670, 31681, 31682, 33150, 39292, 39498, 45847, 45851, 48043, 50156, 51420, 52888, 53199, 53433, 53444, 53445, 53446, 54574, 53199, 56940))
) {
usort($query->posts, "cmp");;
}
return $query;
}
function cmp($a, $b)
{
$res = strcmp(get_post_meta($a->ID, '_event_start_date', true), get_post_meta($b->ID, '_event_start_date', true));
if ( $res == 0) {
$res = strcmp(get_post_meta($a->ID, '_event_start_time', true), get_post_meta($b->ID, '_event_start_time', true));;
}
return $res;
}
// exclude the ARCHIVE category and children from the Project Admin View - doesn't work!!!
add_filter( 'wpv_filter_taxonomy_query', 'exclude_specific_terms_func', 10, 3 );
function exclude_specific_terms_func( $tax_query_settings, $view_settings, $view_id ) {
if($view_id != 16353)
return $tax_query_settings;
$tax_query_settings['exclude_tree'] = array(300);
return $tax_query_settings;
}
add_filter( 'wpv_filter_taxonomy_query', 'exclude_specific_terms_func2', 10, 3 );
function exclude_specific_terms_func2( $tax_query_settings, $view_settings, $view_id ) {
if($view_id != 16701)
return $tax_query_settings;
$tax_query_settings['exclude_tree'] = array(300);
return $tax_query_settings;
}
// allow to add today's date into a CRED form - doens't work?
add_shortcode('wpv-post-today', 'today_shortcode');
function today_shortcode() {
return date( 'F j, Y', current_time( 'timestamp' ));
}
/**
* Shortcode feature: Count the number of children of a hierarchy post (like post_type='page')
* Usuage: [count_children id="123"]
* If the parameter "id" is not set, the shortcode will automatically get the current ID of global $post
*/
function count_children_func( $atts ) {
global $post;
extract( shortcode_atts( array(
'id' => $post->ID,
), $atts ) );
$children = array();
$children = get_pages( 'child_of='. $id );
return count ($children);
}
// show file name only - not whole path
add_shortcode( 'my_file_name', 'wpml_hard_link');
function wpml_hard_link($atts)
{
$val = shortcode_atts( array(
'file_url' => '',
), $atts);
$arr = explode('/',$val['file_url']);
return end($arr);
}
// for greeting card delivery view - if no ids in url, don't show ANY results
add_filter( 'wpv_filter_query', 'empty_post_ids_func', 10, 3 );
function empty_post_ids_func( $query_args, $view_settings, $view_id ) {
if ( $view_id == 19542) {
if(!isset($_GET['post_ids'])){
$query_args['post__in'] = array(-1);
}
}
return $query_args;
}
// for contact management view - if no ids in url, don't show ANY results
add_filter( 'wpv_filter_query', 'empty_post_contactids_func', 10, 3 );
function empty_post_contactids_func( $query_args, $view_settings, $view_id ) {
if ( $view_id == 14221) {
if(!isset($_GET['post_ids'])){
$query_args['post__in'] = array(-1);
}
}
return $query_args;
}
?>
Hello,
The new relationships introduced by the latest Toolset plugins are compatible with old version of Toolset plugins, but you can feedback if there is any new issue.
And I have checked your PHP codes, there isn't any specific codes which are related with post type relationships, so there isn't any special to be updated.
I suggest you backup your website first, then try to upgrade to the latest version of Toolset plugins.