Summery :
# Custom Post Type
# Custom Review or comment of that custom post type.
Please advice me. How can I do this?
]]>...<p><?php do_action( 'et_comment_form_etiqueta' ); ?></p>...
<?php }
}
add_action('et_comment_form_etiqueta','et_choose_etiqueta');
function et_choose_etiqueta(){
#adds 'Ponle Precio' to the comment form ( frontend )
if ( !is_page() ) {
<p>Tu etiqueta:<input type="text" name="et_etiqueta" id="precio" value="aqui va tu etiqueta" size="22" tabindex="3" /></p>
}
}
add_action('comment_post','et_add_etiqueta_commentmeta', 10, 2);
function et_add_etiqueta_commentmeta( $comment_id, $comment_approved ){
#when user adds a comment, check if it's approved
$comment_etiqueta = ( isset($_POST['et_etiqueta']) ) ? $_POST['et_etiqueta'] : 0;
add_comment_meta($comment_id,'et_comment_etiqueta',$comment_etiqueta);
if ( $comment_approved == 1 ) {
$comment_info = get_comment($comment_id);
et_update_post_user_etiqueta( $comment_info->comment_post_ID );
}
}
add_action('comment_post','et_add_etiqueta_commentmeta', 10, 2);
function et_add_etiqueta_commentmeta( $comment_id, $comment_approved ){
#when user adds a comment, check if it's approved
$comment_etiqueta = ( isset($_POST['et_etiqueta']) ) ? $_POST['et_etiqueta'] : 0;
add_comment_meta($comment_id,'et_comment_etiqueta',$comment_etiqueta);
if ( $comment_approved == 1 ) {
$comment_info = get_comment($comment_id);
et_update_post_user_etiqueta( $comment_info->comment_post_ID );
}
}
add_action('et-comment-meta-etiqueta','et_show_comment_etiqueta');
function et_show_comment_etiqueta( $comment_id ){
#displays user comment etiqueta on single post page ( frontend )
$user_comment_etiqueta = get_comment_meta($comment_id,'et_comment_etiqueta',true) ? get_comment_meta($comment_id,'et_comment_etiqueta',true) : 0;
if ( $user_comment_etiqueta <> 0 ) { ?>
<?php echo $user_comment_etiqueta; ?>
<?php }
}
function et_get_top_etiqueta($top_etiqueta) {
global $wpdb;
return $wpdb->get_results($wpdb->prepare("SELECT meta_value, count(*) as countof FROM $wpdb->commentmeta WHERE meta_key = 'et_comment_etiqueta' ORDER BY countof DESC LIMIT 1", $post_id));
}
function et_get_post_user_etiqueta( $post_id ){
#gets under process user (comments) added etiqueta for the post
#this function adds the most popular etiqueta (label) to the post. (it needs to be calculated)
$approved_comments = et_get_approved_comments( $post_id );
if ( empty($approved_comments) ) return 0;
$user_etiqueta = 0;
$approved_comments_number = count($approved_comments);
foreach ( $approved_comments as $comment ) {
$comment_etiqueta = get_comment_meta($comment->comment_ID,'et_comment_etiqueta',true) ? get_comment_meta($comment->comment_ID,'et_comment_etiqueta',true) : 0;
if ( $comment_etiqueta == 0 ) $approved_comments_number--;
$user_etiqueta += $comment_etiqueta;
}
//we need a variable where the most times submitted label is stored.
$result = et_get_top_etiqueta( $top_etiqueta );
# save user rating to the post meta
if ( !get_post_meta($post_id,'_et_inreview_comments_etiqueta',true) ) update_post_meta($post_id,'_et_inreview_comments_etiqueta',$result);
return $result;
}
function et_update_post_user_etiqueta( $post_id ){
#update user added etiqueta for the post
$new_comments_etiqueta = et_get_post_user_etiqueta( $post_id );
if ( get_post_meta($post_id,'_et_inreview_comments_etiqueta',true) <> $new_comments_etiqueta )
update_post_meta($post_id,'_et_inreview_comments_etiqueta',$new_comments_etiqueta);
}
function et_get_approved_comments($post_id) {
global $wpdb;
return $wpdb->get_results($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
}
?>
And this is the where the label (etiqueta) is supposed to appear in the comment box next to each comment submitted by users but IT DOESN’T. The label submitted by each user gets inserted in the database correctly but it just doesn’t get displayed next to the comment in the comment box.
<b>Etiqueta:</b> <?php do_action('et-comment-meta-etiqueta', get_comment_ID());?>
In order to display the most frequently submitted label (etiqueta) next to the post I used this function which can also be found in additional_functions.php above IT DOESNT WORK EITHER!!
<?php add_action('et-comment-meta-etiqueta','et_show_comment_etiqueta'); function et_show_comment_etiqueta( $comment_id ){ #displays user comment etiqueta on single post page ( frontend ) $user_comment_etiqueta = get_comment_meta($comment_id,'et_comment_etiqueta',true) ? get_comment_meta($comment_id,'et_comment_etiqueta',true) : 0; if ( $user_comment_etiqueta <> 0 ) { echo $user_comment_etiqueta; } } function et_get_top_etiqueta($top_etiqueta) { global $wpdb; return $wpdb->get_results($wpdb->prepare("SELECT meta_value, count(*) as countof FROM $wpdb->commentmeta WHERE meta_key = 'et_comment_etiqueta' ORDER BY countof DESC LIMIT 1", $post_id)); }?>
These are the tables that uses the theme:
–wp_commentmeta which has 4 columns: meta_id; comment_id; meta_key; meta_value
–wp_postmeta which has 4 columns: meta_id; post_id; meta_key; meta_value
In my theme I added a custom field into the comment form. In this custom field the user submits a label (a string) for the post (single post) as a comment meta. This user submitted label will be added to wp_commentmeta table et_comment_label as meta_key and the meta_value would be the label (string) submitted by the user. The label (string) that is submitted by most of the users (through the comment form) will be displayed on the post (single post) next to the post content. I need a syntax that counts which is the label that is most frequently submitted. For example:
user 1 submits label: ‘awesome’
user 2 submits label: ‘worthless’
user 3 submits label: ‘awesome’
user 4 submits label: ‘boring’
user 5 submits label: ‘awesome’
As the label ‘awesome’ appears 3 times so that label appears next to the post content.
Anyone can help me to create this syntax?
function connect_add_twitter_field($fields) {
$fields['twitter'] = '<p class="comment-form-twitter"><label>Your Twitter Username</label>'.
'<input id="twitter" type="text" name="twitter" value="@" /></p>';
return $fields;
}
add_filter('comment_form_default_fields','connect_add_twitter_field');
The problem lies in the value field – I tried concatenating it with $_SESSION[‘comment’] but that doesn’t work.
Can someone please help a newbie?
]]>If anyone is looking for a plugin that adds extra comment fields to the wordpress comment section, I have a solution for you!
I spent absolutley ages searching around for something that would work – couldn’t believe it would be so hard to get one measly extra comment field onto the comment form…
Despite trying various solutions, I ended up paying a developer to modify an old one.
For this reason, I am not giving it away (it’s just a few dollars), but will make it free when I have recovered my costs. I am also committed to keeping it up to date.
The plugin allows you to add additional fields to the WordPress Comments Form.
* You can add as many extra comment fields as you like – I’ve set it up with 3 enabled, phone number, age and location. You can see these below on the comment form for this page (feel free to test it).
* You can easily change these, delete these or add additional fields – it’s up to you how many you have!
* Additional fields do not show on the submitted comments, even after you have approved it. This is because these extra comment fields are hidden comments (like the email field) – if you want to be able to display any of the additional fields, this could be achieved by modifying the code (I can provide additional paid support if you need it).
* The additional comments fields do not show in the WordPress dashboard (comments summary section) – but they do show in the admin comments section.
* The additional comments fields do not show in the admin email notification – although this can be enabled with a small change in the plugin code.
* Tested and working on WordPress version 3.02 (Dec 2010)
* Tested and working on Twentyten theme (also tested on several other custom themes)
It works fine in Twentyten and I have also added it to a few other custom themes – so it does work and is easily modifiable with a little bit of HTML / PHP knowledge. If you don’t feel comfortable with modifying the code, I can provide paid support.
More info and the demo, see here: www.solaceten.info
]]>