I am wondering if this is possible, and if so, I’m looking for advice on the best way to approach implementing it.
I want to add extra fields to the comments form for users to leave ratings on three different things:
- Overall Rating
I can somewhat modify the source from this tutorial on extending the comments form… but my issue/question is whether or not it is possible to organize the posts based on these extra comment meta fields.. For example, I want to be able to get all the posts from that particular category based on the score they received in the comment meta. Would I do a custom wp database query? Or is there an even easier way?
The short answer is that yes, it’s possible to get all of the posts from the category based on that score (or any of the other meta data, for that matter), but you’re very limited in your options when it comes to the API.
To my knowledge – and I could be completely off base here – APIs such as
WP_Querydon’t yet support querying data from the
commentmetatable. If they do, it’s not documented in the Codex article and I’ve not peeked at the source code to see if it’s possible in 3.5+.
Depending on how or where you want to filter the data, you may be able to use
wp_list_commentsand provide a custom callback function; however, if I understand your question correctly, it might be better off to write a query using
If you go that route, make sure that you:
prepareto ensure you’re not dealing with illegal input
- Be very careful in how you
JOINso not to pull back posts that are private, in draft, are auto-drafts, are revisions, etc.
- And it sounds like you may be fine using
get_resultsto retrieve what you’re looking for.
Finally, another way that you could make this faster (again, depending on your use case) is to come up with a query that just retrieves the post IDs that you need, then use
WP_Queryto do a proper retrieval of the posts.
The bottom line is that it looks like you may have to do a custom query, but it may not have to be all or nothing.
Consider what options you have and if you can leverage using
$wpdbto pull back as little information as possible, pass the rest of the data to API and let it do its thing as it’s more likely to optimally retrieve the data.
Thanks Tom! Your input is always much appreciated!
I think I may go the $wpdb route (sounds like my cleanest/less painful option) – and then use your suggestion of doing it to just retrieve the Post ID. I think that might be a good method of trying to get what I need accomplished….
- The topic ‘Seeking Advice’ is closed to new replies.