Problem: I have a custom image field and I would like to display a default image if the field has no value.
Solution: Use a series of conditional blocks to display a default image if the field is empty or display the custom field image if the field has some value.
Problem: I am migrating from ACF to Toolset Types custom fields, and I have created a View that shows some of these custom field values. One of my fields shows the old ACF field value and it does not seem to update when I modify the Types field value.
Solution: In this case, the field slugs are slightly different and the shortcode used to display the field used the old ACF field slug. Updating to the new Types field slug solves the problem.
Problem: I would like to display a View of related posts in an M2M relationship. There is checkbox in the intermediary post type (in the relationship) and I would like to display only those related posts where the checkbox is unchecked.
Solution: This requires some custom code, and it also requires that the View is configured to display the intermediary post type. Add the following code snippet to filter by an unchecked checkbox:
add_filter( 'wpv_filter_query', 'unchecked_ints',99,3 );
function unchecked_ints( $query_args,$views_settings, $view_id) {
global $post;
$field_slug = 'release-artist-checked';
$views = array( 48324 ); /* "Collaborations" */
$ints_args = array(
'query_by_role' => 'child',
'role_to_return' => 'intermediary',
'limit' => 1000,
'offset' => 0,
'args' => [
'meta_key' => 'wpcf-' . $field_slug,
'meta_value' => 1,
'meta_compare' => '='
]
);
$ints = toolset_get_related_posts( $post->ID, 'supporting-artists', $ints_args);
// you should not need to edit below this line
if ( in_array( $view_id, $views ) ){
$query_args['post__not_in'] = $ints;
}
return $query_args;
}