Sarah_Frantz
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Sum of all custom field values posted by specific userNVM solved myself.
For those who need it, the following will find all posts by author, then sum up the values of a custom field for each post by that author.
<?php //get current user global $current_user; get_currentuserinfo(); // build query of ids by user $userPosts = get_posts(array('author' => $current_user->ID, 'post_type'=> 'miles')); //change this // loop to create array of ids by user foreach ($userPosts as $post) { setup_postdata($post); $ids[] = get_the_ID(); } $idList = implode(",", $ids); //tun this crap into a list $meta_key = 'miles';//set this to your custom field meta key $allmiles = $wpdb->get_col($wpdb->prepare(" SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %s AND post_id in (" . $idList . ")", $meta_key)); echo '<p>You\'ve completed ' . array_sum( $allmiles) . '</p>'; ?>
Forum: Fixing WordPress
In reply to: show taxonomy related to current taxonomy on pageThe brands are more like categories than tags… would it still work the same?
Forum: Everything else WordPress
In reply to: Seeking organizational opinionsIs there a way to avoid redundancy?
For example, let’s say I have a product that is for ages birth to 12 months, and under $25 AND is brand XYZ, it would appear:
Birth to 12 Months
– XYZ Brand
–ProductUnder $25
– XYZ Brand
–ProductWouldn’t that be redundant? How do you avoid this?
Forum: Everything else WordPress
In reply to: Seeking organizational opinionsOr maybe I just do multiple custom taxonomies, and not do drill downs of one category.
Forum: Fixing WordPress
In reply to: Limit # of times a post displays?I will be sure to update my query, however any insight in avoiding duplicate posting across the sections would be much appreciated.
Forum: Fixing WordPress
In reply to: Limit # of times a post displays?perm=readable only gathers posts that are not marked private
Forum: Fixing WordPress
In reply to: Limit # of times a post displays?here is more from that code, with showposts replaced.
Forum: Fixing WordPress
In reply to: Hopefully a simple query questionRESOLVED. Moved orderby above post type and it works like a charm.
Forum: Fixing WordPress
In reply to: Hopefully a simple query questionI switched it to check for a yes or no and display based on that, which seems to be working now to only show articles with the quote, however it isn’t randomizing it..
$args = array( 'post_type' => 'knowledgebase', 'orderby' => 'RAND', 'showposts' => 1, 'meta_query' => array( array( 'key' => 'show_quote?', 'value' => 'Yes' ) ) ); $quotequery = new WP_Query( $args );
Forum: Fixing WordPress
In reply to: Hopefully a simple query questionI guess I forgot to mention I’m using Advanced Custom Fields, so the field is a custom field value, and it is always present…
Forum: Fixing WordPress
In reply to: Styling first post differently in this particular loopAh, I think I solved this. nvm.
Forum: Fixing WordPress
In reply to: Using Offset in the Loop??Thats what I ended up doing, a css approach. Only problem is it seems like handing off something like that to the next developer whoever handles the site might be confused by it all.
Forum: Fixing WordPress
In reply to: SUM items from Array?Thanks, I actually just got it solved before I saw this – but ended up doing something a little different. This looks much cleaner than my code though haha
Forum: Fixing WordPress
In reply to: Get total value for all comments, for a specific meta_keyAlso, how would you display the resulting average?
Forum: Fixing WordPress
In reply to: Get total value for all comments, for a specific meta_keyWould I do something like this for my query?
SELECT AVG(wp_commentmenta.meta_value) FROM wp_commentmeta, wp_comments WHERE wp_commentmeta.comment_ID = wp_commnets.comment_ID AND wp_comments.comment_post_id = $post->ID AND wp_comments.meta_key = 'performance'