I have a cck field with the name of field_testfield And I have displayed it in the form in .module file like the follwoing.
$form['field_testfield']['#weight'] = 10;
Now I want to enclose it in a fieldset. Any idea about this?
the correct way to implement fieldsets is
$form['my_fieldset'] = array(
'#type' => 'fieldset',
'#weight' => 0,
'#collapsible' => TRUE, //is the fieldset collabsible?
'#collapsed' => TRUE //is the fieldset collabsped at start?
);
to add fields inside this fieldset you would append the elements to the fieldset array
$form['my_fieldset']['custom_field_1'] = array(
'#type' => 'textarea', //or whatever
'#weight' => 0 //the weight set here is the weight of the element inside the fieldset
);
Related
so I am building fairly complex WP site based on WPBakery editor with tons of custom components.
I just found out that some of them need to have multiple textarea_html (WYSIWYG) fields and judging by documentation only one of those fields is allowed per component:
Text area with default WordPress WYSIWYG Editor. Important: only one html textarea is permitted per shortcode and it should have “content” as a param_name
They are defined like this:
array(
'type' => 'textarea_html',
'heading' => __( 'This is WYSIWYG editor', 'text-domain' ),
'param_name' => 'content',
'value' => __( '', 'text-domain' )
),
Adding more with the same type (textarea_html) just converts them (of course, per documentation) to basic textarea field like this:
array(
'type' => 'textarea',
'heading' => __( 'This is basic textarea block', 'text-domain' ),
'param_name' => 'someparamname',
'value' => __( '', 'text-domain' )
),
Any ideas how this could be done differently? Thought about using ACF but didnt had much luck there...
I'm working in a project where based on the design developed i have to reach a different pagination look out.
What i want to achieve is this "<Prev 1/19 Next>"
This is my code so far
<nav class= "pagination">
<?php
echo paginate_links( array(
'current' => $paged,
'total' => $newsPost->max_num_pages,
'aria_current' => 'page',
'show_all' => false,
'prev_next' => true,
'prev_text' => __( '« Prev' ),
'next_text' => __( 'Next »' ),
'end_size' => 0,
'mid_size' => 0,
'type' => 'plain',
));
?>
</nav>
So the previous and next button to show all the time, and in the middle the active page / total number of pages.
Thanks
I have a post type called 'faq' and taxonomy called 'type' within my template and a few taxonomy terms created "Design", "Print", "Display" etc.
The idea I am trying to implement is to display only the posts that belong to assigned taxonomies (types) without duplication. Each post may be assigned to multiple taxonomies (types).
My current code works fine as long as the post have got only one taxonomy assigned to it. As soon as I assign more then one taxonomy it shows duplicate posts like this:
Question 6
Question 5
Question 1
Question 1
Here is my current code:
<?php
$post_type = 'faq';
$tax = 'type';
$faq_types = get_field('types');
$filtered = array();
$termargs = array( 'include' => $faq_types );
$tax_terms = get_terms($tax, $termargs);
if ($tax_terms) {
$i = 1;
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
$tax => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="accordion-section">
<a class="accordion-section-title" href="#accordion-<?php echo $i; ?>"><i class="fa fa-chevron-right"></i> <?php the_title(); ?></a>
<div id="accordion-<?php echo $i; ?>" class="accordion-section-content">
<?php the_content(); ?>
</div>
</div>
<?php
$i++;
endwhile;
}
wp_reset_query();
}
}
?>
I'd really appreciate any help with getting this working the way I need.
Your current loop is saying "For each taxonomy term, show all posts associated with that term", so of course it will duplicate if there is one post associated with multiple terms. Take your query out of the foreach loop and use a single tax query with an array of terms:
$args = array(
'post_type' => $post_type,
'tax_query' => array(
array(
'taxonomy' => $tax,
'field' => 'slug',
'terms' => $term_slugs,
),
),
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
EDIT
By the way, you'll need to convert your array of term objects to an array of term slugs for this to work properly:
$term_slugs = array();
foreach( $tax_terms as $term ) {
$terms_slugs[] = $term->slug;
}
I'd like to display custom posts from specific category in Wordpress in custom page.
My code is:
<?php $loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
?>
I'd like to display post from "loze" category.
Greetings
You can use category_name for this. Amend your WP_Query as follows:
$loop = new WP_Query(
array(
'post_type' => 'product',
'category_name' => 'loze',
'posts_per_page' => -1
)
);
However, I would recommend using the category ID instead (referenced using cat instead of category_name) as it's future-proofed somewhat (you could change the name of the category).
There is lots of information on this in the category section of the WordPress Codex for WP_Query.
I have a navigation and use it for breadcrumbs. I want to use it for top menu too , but I don't want to show my products in top menu.
How Can I achieve that ?
Add a custom attribute while defining the array in the module.config.php -
Eg:
array(
'label' => 'Product List',
'route' => 'product',
'action' => 'index',
'resource' => 'Product\Controller\Product:index',
'top_menu' => '0',
),
For the rest of the arrays set the top_menu attribute to 1.
In the partial file of top-menu, check -
<?php foreach ($this->container as $page) {
[...]
if($page->get('top_menu') == '1') {
//Code to display the menu.
}
[...]
} ?>
I hope it gives some idea.