Forum Replies Created
-
AuthorPosts
-
jonwatson87
ParticipantWorking again now... :/ Maybe it just took a bit of time for everything to clear and I was being impatient? Things usually start working immediately after a cache clear! Sorry! Overreacting, AGAIN.
jonwatson87
Participant//Panelists $meta_boxes[] = array( 'title' => 'Panelists', 'context' => 'normal', 'priority' => 'high', 'post_types' => 'events', 'desc' => '(drag to reorder)', 'fields' => array( array( 'id' => 'radix_panelists', 'type' => 'group', 'clone' => true, 'sort_clone' => true, 'fields' => array( array( 'name' => 'Position', 'id' => $prefix . 'panelistposition', 'type' => 'text', 'desc' => 'Position on panel: e.g. Panelist, or Chair', ), array( 'name' => 'Name', 'id' => $prefix . 'panelistname', 'type' => 'text', 'desc' => 'Name of panelist', ), array( 'name' => 'Title', 'id' => $prefix . 'panelisttitle', 'type' => 'text', 'desc' => 'Title of panelist', ), array( 'name' => 'URL', 'id' => $prefix . 'panelisturl', 'type' => 'text', 'desc' => 'Link or mailto: for panelist', ), array( 'name' => 'Profile Pic', 'id' => $prefix . 'panelistpic', 'type' => 'file_input', 'desc' => 'Profile picture of panelist', ), ), ), ), );jonwatson87
ParticipantNo worries, Anh! Hope you figure it out ๐ Not a problem to bypass it with a checkbox as long as people are aware of the issue.
jonwatson87
ParticipantConfirmed. The default white space is somehow being saved as a populated field when the post is updated.
I renamed the group and the if !empty worked. I updated a post, leaving these fields blank, and it stopped working.
Even if these fields are left blank, the empty fields still register as being content and if !empty returns true.
I'm gonna use a checkbox to hide this section for now and query that instead.
jonwatson87
ParticipantAwesome! ๐
Thanks, Anh!
jonwatson87
ParticipantFull code, if it helps anyone in future (note that I had to adapt it slightly for use with Co-Authors Plus, so it echoes user_login with the prefix cap- and then uses that in the tax_query):
// Return an array of radix_authoraccount, if not empty, for management, board and fellows post types $teamargs = array( 'post_type' => array('management','fellows','board'), 'posts_per_page' => -1, ); $team_posts = wp_get_recent_posts( $teamargs ); $theteamauthors = array(); foreach( $team_posts as $teamauthors ) { if (rwmb_meta( 'radix_authorcheckbox', '', $teamauthors['ID']) == 1 ) { $teamauthorlist = rwmb_meta( 'radix_authoraccount', '', $teamauthors['ID']); $getpostauthor = get_user_by( 'id', $teamauthorlist ); $authorlogin = $getpostauthor->user_login; $theteamauthors[] = array('cap-' . $authorlogin); } } // Sort array to remove duplicate authors // print_r($teamauthorlist); $authorarray = array_unique($theteamauthors, SORT_REGULAR); $authormap = array_map('array_pop', $authorarray); $theauthors = implode(",",$authormap); // echo $theauthors; // Run query to retrieve active posts by these authors $args = array( 'numberposts' => '10', 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => array( 'post', 'work', 'news' ), 'meta_query' => array( array( 'key' => 'radix_status', 'value' => 'value1', 'compare' => '==', ) ), 'tax_query' => array( array( 'taxonomy' => 'author', 'field' => 'slug', 'terms' => explode(',', $theauthors) ) ) ); $recent_posts = new WP_Query ($args); if ( $recent_posts->have_posts() ) { echo '<div class="teamworklist"><ul>'; while ( $recent_posts->have_posts() ) { $recent_posts->the_post(); // Post Title $title = apply_filters( 'genesis_post_title_text', get_the_title() ); echo '<li>'; echo sprintf( '<h1 class="team-work entry-title"><a href="%s" rel="bookmark">%s</a></h1>', get_permalink(), $title ); // Post Date echo get_the_date(); echo '<br>'; // Authors echo 'By '; coauthors_posts_links(); echo '</li>'; } echo '</ul></div>'; } else { }jonwatson87
ParticipantGOT IT!
Seems that the "user" field has a value even if it isn't selected, hence my need to put in a checkbox to begin with.
I changed the if statement to the checkbox value and returned radix_authoraccount values based on that, instead.
Final, working code:
// Return an array of radix_authoraccount, if not empty, for management, board and fellows post types $teamargs = array( 'post_type' => array('management','fellows','board'), 'posts_per_page' => -1, ); $team_posts = wp_get_recent_posts( $teamargs ); $teamauthorlist = array(); foreach( $team_posts as $teamauthors ) { if (rwmb_meta( 'radix_authorcheckbox', '', $teamauthors['ID']) == 1 ) { $teamauthorlist[] = array(rwmb_meta( 'radix_authoraccount', '', $teamauthors['ID'])); } } // Sort array to remove duplicate authors // print_r($teamauthorlist); $authorarray = array_unique($teamauthorlist, SORT_REGULAR); $theauthors = array_values( $authorarray ); print_r($theauthors);Thanks for being my sounding board!
jonwatson87
ParticipantLatest update:
I got it returning SOME values, by using:
// Return an array of radix_authoraccount, if not empty, for management, board and fellows post types $teamargs = array( 'post_type' => array('management','fellows','board'), ); $team_posts = wp_get_recent_posts( $teamargs ); $teamauthorlist = array(); foreach( $team_posts as $teamauthors ) { if ( !empty( array(rwmb_meta( 'radix_authoraccount', '', $teamauthors['ID']) ) ) ) { $teamauthorlist[] = array(rwmb_meta( 'radix_authoraccount', '', $teamauthors['ID'])); } } // Sort array to remove duplicate authors print_r($teamauthorlist); $authorarray = array_unique($teamauthorlist, SORT_REGULAR); $theauthors = array_values( $authorarray ); // print_r($theauthors);'But the values returned aren't quite right... According to the user data I can see, and the users assigned using radix_authoraccount, I should be getting:
234455678
Instead, the above code is returning:
2333445578
That's two extra 3s and a missing 6... Getting closer, but something's not quite right...
jonwatson87
ParticipantSo, I've got the array and sorting to work, but not with radix_authoraccount... if I change 'radix_authoraccount' to a standard post field, like 'post_title', and 'SORT_NUMERIC' to 'SORT_REGULAR' (because title is no longer a numeric value) it works perfectly - printing the array of values minus the two duplicates.
Any idea how I can get this to work with 'radix_authoraccount'?
// Return an array of radix_authoraccount, if not empty, for management, board and fellows post types $teamargs = array( 'post_type' => array('management','fellows','board'), ); $team_posts = wp_get_recent_posts( $teamargs ); $teamauthorlist = array(); foreach( $team_posts as $teamauthors ) { if ( !empty( array($teamauthors['radix_authoraccount']) ) ) { $teamauthorlist[] = array($teamauthors['radix_authoraccount']); } } // Sort array to remove duplicate authors $authorarray = array_unique($teamauthorlist, SORT_NUMERIC); $theauthors = array_values( $authorarray ); print_r($theauthors);jonwatson87
Participant100% correct! Sorry, Anh! Feel like an idiot now! Clearing the cache is usually the first thing I do! XD
Thanks so much for the help!
jonwatson87
ParticipantOkay, loading fine on the front end now! Must've mis-copied/pasted something.
Still not letting me add more than 1 group record, however...
May 30, 2016 at 11:21 PM in reply to: Group and file_upload (AND clone) : only 1st file_upload is considered #3221jonwatson87
ParticipantSame issue - group will only save one record. Any new records added just replace the first one.
Whereabouts is the new code on GitHub?
jonwatson87
ParticipantNevermind! I think I've figured it out ๐
jonwatson87
ParticipantCompletely uninstalled the plugins, downloaded the very latest versions and reinstalled. Seems to have done the trick!
jonwatson87
ParticipantOkay, I've fixed the front end issue by replacing "rwmb_get_field" calls with "rwmb_meta"
However, still having the back end issue that posts and metaboxes aren't showing up properly.
-
AuthorPosts