Forum Replies Created
-
AuthorPosts
-
Enrico Franci
ParticipantSolved with a flexible shortcode solution
function list_terms_custom_taxonomy( $atts ) { // Inside the function we extract custom taxonomy parameter of our shortcode extract( shortcode_atts( array( 'custom_taxonomy' => '', ), $atts ) ); // arguments for function wp_list_categories $args = array( 'taxonomy' => $custom_taxonomy, 'title_li' => '' ); if ($custom_taxonomy = 'categorie') { $widget_title = 'Catégories'; } else if ($custom_taxonomy = 'collection') { $widget_title = 'Collections'; } // We wrap it in unordered list echo '<h2 class="widget-title">' .$widget_title. '</h2><ul class="cat-list">'; echo wp_list_categories($args); echo '</ul>'; } // Add a shortcode that executes our function add_shortcode( 'ct_terms', 'list_terms_custom_taxonomy' ); //Allow Text widgets to execute shortcodes add_filter('widget_text', 'do_shortcode');Enrico Franci
ParticipantNot solved because in the sidebar I get the list of the specific post and not the complete list of registered taxanomy terms!
Enrico Franci
ParticipantSolved by this function...
function wpdocs_custom_categories_terms_links() { // Get post by post ID. if ( ! $post = get_post() ) { return ''; } // Get post type by post. $post_type = $post->post_type; // Get post type taxonomies. $taxonomies = get_object_taxonomies( $post_type, 'livre' ); $out = array(); foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){ // Get the terms related to post. $taxonomy = 'categorie'; $terms = get_the_terms( $post->ID, $taxonomy_slug ); if ( ! empty( $terms ) ) { $out[] = "<ul>"; foreach ( $terms as $term ) { $out[] = sprintf( '<li class="cat"><a href="%1$s">%2$s</a></li>', esc_url( get_term_link( $term->slug, $taxonomy_slug ) ), esc_html( $term->name ) ); } $out[] = "\n</ul>\n"; } } return implode( '', $out ); }Enrico Franci
ParticipantHello I tried to get something like to be have a list of all the taxonomy list in a sidebar widget but I get only a blank space of the item in hmtl content space.
<?php $terms = get_terms( array( 'taxonomy' => 'categorie', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, )); if ( empty( $terms ) || is_wp_error( $terms ) ) { return; } foreach( $terms as $term ) { $cat_title= rwmb_meta( 'categorie', ['object_type' => 'term'], $term->name ); echo '<ul><li>'; echo'<a href="'. get_term_link( $term ) .'">'. $cat_title . '</a>'; echo '</li></ul>'; } ?>https://www.maxxdesign.it/gremesefr/livre/ghost/
Can you explain me where is the bug in my code?
Enrico Franci
ParticipantI managed to solve part of the loop query but the associated image in group fields (a single uploaded file) is not still visible in frontend; here the code I used
<?php $extras = rwmb_meta( 'extra' ) ?: []; ?> <?php $link = get_the_permalink(); ?> <?php foreach ( $extras as $extra ) { echo '<div class="card">'; $group = rwmb_meta( 'extra' ); $image_ids = $group['images'] ?? []; if ( $image_ids ) { foreach ( $image_ids as $image_id ) { $image = RWMB_Image_Field::file_info( $image_id, ['size' => 'my-image-size'] ); echo '<img src="' . $image['url'] . '">'; } } ?> <?php echo '<h5 class="book-author"><a href="' .$link. '">' .$extra['author_name'] .' ' .$extra['author_surname']. '</a></h5>'; ?> <?php echo '</div>'; } ?>But the html output is
without pictEnrico Franci
ParticipantHello
I had a simlar problem that I tried to solve switching to a clonable group of fields (this is a book catalogue and in some cases I need to add the authors names with pictures, but only to make them visible in the authors' list page).
Following and aexample showed on Mteboax Group page I create this group in $meta_boxes:[ 'name' => esc_html__( 'Autori vari', 'online-generator' ), 'id' => 'extra', 'type' => 'group', 'clone' => true, 'clone_as_multiple' => true, 'sort_clone' => true, 'add_button' => '+ Aggiungi nuovo', // List of sub-fields. 'fields' => [ [ 'type' => 'text', 'name' => esc_html__( 'Nome', 'online-generator' ), 'id' => 'author_name', ], [ 'type' => 'text', 'name' => esc_html__( 'Cognome', 'online-generator' ), 'id' => 'author_surname', ], [ 'type' => 'image', 'name' => esc_html__( 'Foto', 'online-generator' ), 'id' => 'author_pict', 'max_file_uploads' => 1, ],Then following the query example I added this code in the page template:
<?php $authors = rwmb_meta( 'extra' ); if ( ! empty( $authors ) ) { foreach ( $authors as $author ) { echo '<h4>', 'Auteurs d\'Ouvrages Collectif', '</h4>'; echo '<p>', 'Prénom:', ' ', $author['author_name'], '</p>'; echo '<p>', 'Nom:', ' ', $author['author_surname'], '</p>'; } } ?>But the query issue is only blank!
Instead the query to normal fields (not in clonable group) let me show the books' authors in perfect descending surname order.
See the page hereEnrico Franci
ParticipantHi
I updated the query but onle the first author is bivible and the picture is not loaded<?php $new_args = array( 'post_type' => 'livre', 'meta_query' => array( array( 'key' => 'edgr_cloned_surname', ) ), 'posts_per_page' => '-1', 'order' => 'ASC', 'orderby' => array( 'edgr_cloned_surname' => 'ASC', ) ); ?> <?php $new_query = new WP_Query( $new_args ); ?> <?php if ($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post(); ?> <div class="card"> <?php $link = get_the_permalink(); $author_c_surname = get_post_meta($post->ID, 'edgr_cloned_surname', true); $author_c_name = get_post_meta($post->ID, 'edgr_cloned_name', true); ?> <?php $images_c = get_post_meta($post->ID, 'edgr_cloned_author_img', true);?> <?php $images_c = rwmb_meta( 'edgr_cloned_author_img', ['limit' => 1] ) ?> <?php $image = reset( $images_c ) ?> <img class="bio" src="<?= $image['url']; ?>"> <?php echo '<h5 class="book-author"><a href="' .$link. '">'.$author_c_name.' '.$author_c_surname.'</a></h5>'; ?> </div> <?php endwhile; endif; ?>test page is here:
Enrico Franci
ParticipantI built a field group to manage books in a catalogue where there are multiple authors for a single book (on frontend will not be shown the authors surnames but only the text 'Ouvrage collectif')
The problem comes when I try to retreive all the authors in alphabetical order (eventually is there a picture too, but the question is secondary!).
The query to clonable fields gives me a blank space...
I tried to set a * in array or a blank space or all the capital letters from A to Z.
My deal is to retreive all the author's surname then match them with names and with uploaded picture file.
The same code - using a single text input - for books with only one author - works fine:Here the code used for field group and query
$prefix = 'edgr_'; $meta_boxes[] = [ 'title' => esc_html__( 'Inserimento Autori vari', 'online-generator' ), 'id' => 'bookauthors', 'post_types' => ['livre'], 'context' => 'after_title', 'autosave' => true, 'fields' => [ [ 'type' => 'text', 'name' => esc_html__( 'Cognome', 'online-generator' ), 'id' => $prefix . 'cloned_surname', 'desc' => esc_html__( 'inserire cognome', 'online-generator' ), 'clone' => true, ], [ 'type' => 'text', 'name' => esc_html__( 'Nome', 'online-generator' ), 'id' => $prefix . 'cloned_name', 'desc' => esc_html__( 'inserire nome', 'online-generator' ), 'clone' => true, ], [ 'type' => 'image', 'name' => esc_html__( 'Image', 'online-generator' ), 'id' => $prefix . 'cloned_author_img', 'clone' => true, ], ], ];-----
$new_args = array( 'post_type' => 'livre', 'meta_query' => array( array( 'key' => 'edgr_cloned_surname', 'value' => serialize( array( ????? ) ), 'compare' => 'LIKE', ) ), 'posts_per_page' => '-1', 'order' => 'ASC', 'orderby' => array( 'edgr_cloned_surname' => 'ASC', ) ); ?> <?php $new_query = new WP_Query( $new_args ); ?> <?php if ($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post(); ?> <div class="card"> <?php $author_c_surname = get_post_meta($post->ID, 'edgr_cloned_name', true); $author_c_name = get_post_meta($post->ID, 'edgr_cloned_surname', true); ?> <?php echo '<h5 class="book-author"><a href="' .$link. '">'.$author_c_name.' '. $author_c_surname.'</a></h5>'; ?> </div> <?php endwhile; endif;Enrico Franci
ParticipantI created a select field in Metabox CPT backend that has two values
<div>
'type' => 'select',
'name' => esc_html__( 'Collection', 'online-generator' ),
'id' => $prefix . 'collection',
'options' => [
'Roma Livres' => esc_html__( 'Roma Livres', 'online-generator' ),
'Hors Collection' => esc_html__( 'Hors Collection', 'online-generator' ),
],
</div>
The I try to retreive the selected value in frontend post tempalte using this code:<div>
<?php $collection = get_post_meta( $post->ID, $value, 'edgr_collection', true );?>
<div class="isbn">Collection: <?php echo $collection ?>
</div>
</div>
But the output is "Array" (all other fields type are printed correctly!)Example URL below:
September 5, 2023 at 10:30 PM in reply to: Validation Rule - Option to validate multiple inputs #43146Enrico Franci
ParticipantHello
is there a way to set a limit (maximum) of choices in a multiselect dropdown field? -
AuthorPosts