tiedemies
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesSounds very good. There might be need for couple of additonal categories in the future, so being able to add them easily is a great thing.
Adding the stripped HTML and JS should not be a problem, but then again, that’s what I thought of this very issue at first ??
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesIt looks better already. I’ll gladly admit that my code was a bit clumsy.
} elseif (is_author()) {
Sorry about that, it was an old leftover from the time when the profile page code was in archive.php. I think it was better to separate the two and have archive in its own and profile/author in other file.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesYes, author.php.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesauthor data – name, website, etc
posts (questions) – from work category
comments (answers) – from posts in the work category
posts (questions) – from edutcation category
comments (answers) – from posts in the education categoryYes, that’s correct. That is how I intended it to work.
You are also correct about the amount of queries, how busy the site will be is anybody’s guess, but I agree that there could be troubles ahead.
If you have the time and willingness, I would definitely appreciate the effort. I’ve been stuck with this for some time now.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesYes, it is local install, but here is the member profile page code.
[code removed] - by t31os
Replaced with pastebin.
https://wordpress.pastebin.com/KCPwVDBQAll I need is a way to get the profile page show questions (comments) made to posts that belong in category "education", under the "education answers" tab and the same thing for "work" category.
First I thought it is going to be easy, but boy was I wrong.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesNo multiple categories here, when user posts a question (post) he can choose only one category.
Code for the page where questions are asked is as follows (this is one single php file):
<?php if ( $_POST['question_post'] == '1') { $question_title = $_POST['question_title']; $question_content = $_POST['question_content']; $question_category = $_POST['cat']; $message = post_new_question($question_title, $question_content, $question_category); } get_header(); ?> <div id="main"> <div id="mainContent"> <!-- Center Column --> <div id="centerCol" class="left"> <!-- Search Form --> <?php get_search_form(); ?> <!-- Search Form --> <!-- Tabs Content Blocks --> <div class="Box1"> <div class="BoxInner"> <h2><?php the_title(); ?></h2> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php display_message($message) ?> <?php // If logged in change nav to My Account and Log Out if ( is_user_logged_in() ) { ?> <div class="post" id="post-<?php the_ID(); ?>"> <form method="post" action="" id="postNewQuestion" name="postNewQuestion"> <label>Select a Question Category:<span class="asterixRequired">*</span></label> <div class="catselect"> <?php wp_dropdown_categories('orderby=name&hide_empty=0&exclude=1,7,8&hierarchical=1') ?></div><br/> <label>Question Title:<span class="asterixRequired">*</span></label> <fieldset><input type="text" name="question_title" id="question_title" size="30" value="<?php echo $_POST['question_title']?>" /></fieldset> <label>Question Description:<span class="asterixRequired">*</span></label> <fieldset><textarea rows="10" cols="40" name="question_content" id="question_content"><?php echo $_POST['question_content']?></textarea></fieldset> <input type="hidden" name="question_post" value="1" /> <div class="divider"></div> <div class="addQuestion"><input type="image" name="submit_question" id="submit_question" src="<?php bloginfo('template_url'); ?>/images/add-question-btn.png" value="Send" /></div> </form> <?php // the_content(); ?> </div> <?php } else { ?> <?php redirect_to_login_url(); ?> <?php }; ?> <?php endwhile; endif; ?> </div> </div> <!-- Tabs Content Blocks --> <div class="reset"></div> </div> <!-- / Center Column --> <?php get_sidebar(); ?> </div> </div> <!-- / Main Section --> <?php get_footer(); ?>
Then there’s the code for profile page which I posted and the functions.php snippet. In functions.php there is also the following related to answers (comments):
function post_new_answer($answer_content){ include ( ABSPATH . 'wp-load.php' ); $answer_content_stripped = strip_tags($answer_content); global $wp_query; $question_id = $wp_query->post->ID; $question_author_id = $wp_query->post->post_author; $user = wp_get_current_user(); global $wpdb; $gather_comments = "SELECT * FROM ".$wpdb->prefix."comments WHERE comment_post_ID = '" . $question_id . "' ORDER BY comment_date"; $user_comments = $wpdb->get_results($gather_comments); if(isEmptyString($answer_content_stripped)) return new WP_Error('forgot_answer', 'You forgot to enter your Answer.'); foreach ($user_comments as $user_comment) { if ($user_comment->comment_author == $user->user_login ) { if ($user_comment->comment_content == $answer_content_stripped) { return new WP_Error('duplicate_user_comment_on_question', 'You have already answered this exact answer for this question.'); } else {} } else {} } // Define the Answer Data $comment_author = $user->user_login; $comment_author_email = $user->user_email; $comment_post_ID = $question_id; $comment_parent = $question_id; $comment_content = $answer_content_stripped; $user_ID = $user->ID; $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_content', 'comment_parent', 'user_ID'); $comment_id = wp_new_comment( $commentdata );
Now, I am still quite an amateur with php and I might be trying something too ambitious, but I would think that comments made to posts in certain categories should be able to separate and show in different places, like in my case, tabs.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesEvery post is only assigned to one category.
The current problem is that if I have categories “education” and “work” and comment a post in education category, the comment shows under both “education” and “work” in user’s profile page.
But when commenting a post in “work” category, the comment shows under “education”, but not “work”.
Your code I think works perfect, it is just that for some reason I cannot get the comments to show in right places.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesWell, it’s almost working. In fact I think your code solves the problem, I just cannot get the answers in right categories.
I have two categories and when a question is posted in other, it shows in both and in other category the question appears in just the opposite.
Thank you very, very much for your help though.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesWhat I’m trying to do is this: When the user answers (comments) a question in a certain category (i.e. education), he could see that and his other previous answers on his profile page under “education”.
To be honest, I am not sure if this is even possible, but I figured that when it is possible to show the comments the user has made, it is possible to get them based on what category the post he commented was in.
Forum: Fixing WordPress
In reply to: get user comments from certain categoriesSorry about that.
<?php $comments = getUserAnswers($curauth->ID); if (!empty($comments)) { ?>
That’s just before the first snippet.
function getUserAnswers($user_id){ global $wpdb; $gather_comments = "SELECT * FROM ".$wpdb->prefix."comments WHERE user_id = '" . $user_id . "' ORDER BY comment_date DESC LIMIT 10"; $user_comments = $wpdb->get_results($gather_comments); return $user_comments; }
And that is in the functions.php.
Forum: Fixing WordPress
In reply to: Conditional textAnd there it is! Works like a charm. thank you Nouveller, thank you very much.