Problem: After two days have passed from the time of post creation, I would like to display some text on my post that says the post has expired.
Solution: Use two separate custom date fields to store the post creation timestamp and the post expiration timestamp. Use a custom function or custom shortcode to compare the expiration timestamp with the current timestamp. The following code example shows how to set the two requested custom field values:
//FECHA AUTOMÁTICA BONOS
add_action( 'save_post', 'tssupp_auto_set_date_fields', 100, 3 );
function tssupp_auto_set_date_fields( $bonos, $post, $update ) {
$post_type = 'bonos';
$created_field_slug = 'fecha-de-creacion-del-bono'; // edit your created field slug here
$expiration_field_slug = 'fecha-de-caducidad'; // edit your expiration field slug here
// do not edit below this line
$created_field_value = get_post_meta($bonos, 'wpcf-' . $created_field_slug, true);
$expiration_field_value = get_post_meta($bonos, 'wpcf-' . $expiration_field_slug, true);
if ( $post->post_status == 'publish' && $post->post_type == $post_type && !$created_field_value ) {
update_post_meta( $bonos, 'wpcf-' . $created_field_slug, date('U') );
}
if ( $post->post_status == 'publish' && $post->post_type == $post_type && !$expiration_field_value ) {
update_post_meta( $bonos, 'wpcf-' . $expiration_field_slug, (date('U') + 172800) );
}
}
Problem: I have a custom URL field that my visitors populate using a front-end Form. The URL is a YouTube video URL, and I would like to display the video in an embedded player with the URL parameter rel=0 attached so no related videos are displayed. However, I do not expect my Users to add the rel=0 parameter when they enter the YouTube URL on the front-end. How can I append the URL parameter programmatically in the template when the video is displayed?
Solution: You need a custom shortcode to do this. The following can be used as a guide:
Replace your-field-slug with the slug of the field containing the URL, and adjust the height and width of the embed shortcode as needed. Render the player with the custom shortcode, like this:
Problem:
The user would like to filter a map by zipcode.
Solution:
Maps cannot be filtered by zipcodes, they can only be filtered by distance.
To be able to filter by zipcode, add a custom field for zipcode, and filter with it.
Problem:
The user is not able to add a new custom field with a specific slug, because the field already exists and would like to remove it.
Solution:
Note that you can reuse existing custom fields in different field groups, check this screenshot http://prntscr.com/vj57sy
If you need to remove the existing field, go to Toolset->Custom Fields, scroll down and click on "Post Field Control", check this screenshot http://prntscr.com/vj58i3