Frontier Post – Custom Fields
If you want to implement custom field support for Frontier Post, you you can now do this by adding code to your functions.php in your child theme – Below example adds a Rating field:
Custom fields requires fairly advanced php and WordPress skills. Custom fields will not be supported, unless there is a bug in the Frontier Post code – In other words, I cannot support your custom code.
Updated February 2017
//***************************************************************************************
//* Add custom fields to Frontier Post
//***************************************************************************************
// ********* Text field - Buttom of form *******
function fp_my_custom_text_field( $thispost, $tmp_task_new)
{
// New table cell containing additional fields
echo '<tr><td class="frontier_no_border">';
echo '<fieldset class="frontier_post_fieldset_additional">';
echo '<legend>Additional fields</legend>';
// a table to hold the fields and ensure alignment
echo '<table class="frontier_no_border"><tr>';
// Simple text field
$simple_txt_fld = get_post_meta( $thispost->ID, 'fp_text_fld', true );
echo '<td class="frontier_no_border">Text field:</td>';
echo '<td class="frontier_no_border">';
echo '<input name="fp_text_fld" id="fp_text_fld" value="'.$simple_txt_fld.'" size="40" type="text">';
echo '</td>';
echo '</tr></table>';
echo '</fieldset>';
echo '</td></tr>';
}
// add the action
add_action( 'frontier_post_form_standard_top', 'fp_my_custom_text_field', 10, 2 );
// ********* Rating field - Buttom of form *******
function fp_my_custom_rating( $thispost, $tmp_task_new)
{
// New table cell containing additional fields
echo '<tr><td class="frontier_no_border">';
echo '<fieldset class="frontier_post_fieldset_additional">';
echo '<legend>Additional fields</legend>';
// a table to hold the fields and ensure alignment
echo '<table class="frontier_no_border"><tr>';
// rating field
$rating = intval(get_post_meta( $thispost->ID, 'fp_rating', true ));
echo '<td class="frontier_no_border">Rating:</td>';
echo '<td class="frontier_no_border">';
$tmp_html = '<select class="frontier_post_dropdown" name="fp_rating" id="fp_rating" >';
$tmp_html .= '<option value="0"'.($rating == 0 ? ' selected="selected" >' : '>').'Not rated</option>';
// Build from 1 to 5 star rating
for ($i = 1; $i <= 5; $i++)
{
$tmp_html .= '<option value="'.$i.'"'.($rating == $i ? ' selected="selected" >' : '>').$i.' Stars</option>';
}
$tmp_html = $tmp_html.'</select>';
echo $tmp_html;
echo '</td>';
echo '</tr></table>';
echo '</fieldset>';
echo '</td></tr>';
}
// add the action
add_action( 'frontier_post_form_standard', 'fp_my_custom_rating', 10, 2 );
// *** End display frontier post custom fields
//***************************************************************************************
//* Get custom field values, and save them
//***************************************************************************************
function fp_save_my_custom_fields($tmp_post, $tmp_task_new, $input_values )
{
// Rating
if ( array_key_exists('fp_rating', $input_values) )
{
update_post_meta($tmp_post->ID, 'fp_rating', intval($input_values['fp_rating']) );
}
// Text Field
if ( array_key_exists('fp_text_fld', $input_values) )
{
update_post_meta($tmp_post->ID, 'fp_text_fld', $input_values['fp_text_fld'] );
}
}
add_action( 'frontier_post_post_save', 'fp_save_my_custom_fields', 10, 3 );
// ** End save Frontier Post Custom fields **
Comments
Frontier Post – Custom Fields — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>