I have 7 pages about services.
In documentation of Redux Framework explain the class select and multi select
Example Multi Select code:
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
//Must provide key => value pairs for radio options
'options' => array(
'1' => 'Opt 1',
'2' => 'Opt 2',
'3' => 'Opt 3'),
'default' => array('2','3')
);
How I do for in options insert dynamically all pages ids or posts ids registered in DB?
UPDATED
Redux::setSection($opt_name, array(
'id' => 'options_services',
'title' => 'Services',
'subsection' => true,
'fields' => array(
array(
'id' => 'opt-multi-select_pages',
'type' => 'select',
'multi' => true,
'title' => 'Multi Select Option',
'data' => 'pages', // select pages
'args' => array( 'posts_per_page' => -1 ),
'default' => array('1','2','3','4','5')
)
)
));
index.php
<?php
foreach ($global_master['options_services'] as $singleValue){
?>
<div class="col-md-6 col-sm-6">
<div class="service-item">
<h4> <strong><?php echo $singleValue['post_title'] ?> </strong></h4>
<img src="<?php echo $singleValue['post_thumbnail_url'] ?>" alt="..." class="img-thumbnail img-responsive">
See More
</div>
</div>
<?php
}
?>
The above code does not return anything in the index
In the code I Try use returns 'post_title' and 'guid' indicated in documentation wordpress and not have references of 'post_thumbnail_url.'
UPDATED 2
I was able to solve my initial doubt with the help of Nathan Dawson and to print I used the code below:
<?php
foreach ($global_master['opt-multi-select_pages'] as $singleValue){
$post_thumbnail_id = get_post_thumbnail_id($singleValue);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
?>
<div class="col-md-6 col-sm-6">
<div class="service-item service">
<h4> <strong><?php echo get_the_title($singleValue); ?> </strong></h4>
<img src="<?php echo $post_thumbnail_url; ?>" alt="..." class="img-thumbnail img-responsive">
See more
</div>
</div>
<?php
}
?>
Fields in the Redux Framework have the option to dynamically list pages out of the box, you simply need to set the argument. Drop 'options' and set a value for 'data' instead.
Example:
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
'data' => 'pages', // select pages
'args' => array( 'posts_per_page' => -1 ),
'default' => array('2','3')
);
You may notice I've also added the 'args' option. The pages 'data' option will retrieve 20 by default, the custom args retrieve all pages instead.
Documentation: https://docs.reduxframework.com/core/the-basics/using-data-argument/
Try this.
//$page_id_array store your all page ids
$page_id_array = get_all_page_ids();
//$options will store multi select options.
$options = array();
foreach( $page_id_array as $page_id ){
$options[$page_id] = get_the_title($page_id);
}
$fields = array(
'id' => 'opt-multi-select',
'type' => 'select',
'multi' => true,
'title' => __('Multi Select Option', 'redux-framework-demo'),
'subtitle' => __('No validation can be done on this field type', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
//Must provide key => value pairs for radio options
'options' => $options,
'default' => array('2','3'),
);
Related
I created a custom field with 'domain_url' id to add field in my taxonomy using the following code:
acf_add_local_field_group(array(
'key' => 'group_6294fa89c564b',
'title' => 'Domain url Field',
'fields' => array(
array(
'key' => 'field_629504c3cdd67',
'label' => 'domain url',
'name' => 'domain_url',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'taxonomy',
'operator' => '==',
'value' => 'news_source',
),
),
),
));
And I want to get the value inside the categories foreach, I tried this code but it didn't give a result
<?php
$args = array(
'taxonomy' => 'news_source',
);
$cats = get_categories($args);
foreach($cats as $cat) {
?>
Name: <?php echo $cat->name; ?> >
Domain: <?php echo get_field('domain_url' ); ?> <br/>
<?php
}
?>
Is the problem in the code? Or does the extension not support it?
You are missing an argument in your get_field(). You need to add an arg for the term or term object.
<?php
$args = array(
'taxonomy' => 'news_source',
);
$cats = get_categories($args);
foreach($cats as $cat) {
?>
Name: <?php echo $cat->name; ?> >
Domain: <?php echo get_field('domain_url', $cat ); ?> <br/> // Put the term in here.
<?php
}
?>
In this case you may need an extra query, or to use the term string plus the term ID in a string.
This ACF documentation article shows some different methods of retrieving tax term fields as well.
I am building a website using Advanced Custom Fields that has yachts for sale. The yachts use a custom Post type called ‘yachts’
One of the fields in the individual yacht listing is a true/false value to determine wether it should be a featured listing. (it was originally a checkbox but I changed it after experimenting with the answer in this post)
Advanced custom fields: can't query posts by custom field
I am trying to display previews of the featured listings on the home page but I can’t get it to work.
I originally tried this code from the ACF documentation
edit: I started with just trying to fetch the title but I also need the additional fields
<section class="featured-yachts">
<h2>FEATURED YACHTS</h2>
<?php
// args
$args = array(
'numberposts' => -1,
'post_type' => 'yachts',
'meta_key' => 'featured',
'meta_value' => 'yes'
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</section>
And now have this after switching to a true false field
<section class="featured-yachts">
<h2>FEATURED YACHTS</h2>
<?php
$args = array(
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'featured',
'value' => '1',
'compare' => 'LIKE',
)
),
);
$my_posts = new WP_Query($args);
if ($my_posts->have_posts()) {
while ($my_posts->have_posts()) : $my_posts->the_post();
echo get_the_title();
endwhile;
wp_reset_postdata();
}
?>
</section>
I have also tried editing this: How filter custom posts by Advanced Custom Fields checkbox
but again, I cant get it to work.
The most any of these return is the h3 title
I can't work out what the issue is.
Thanks in advance for any help
edit : I have at least one post using the custom post type 'yachts' that is set to true for featured.
I still have lots of fields to add, but I would have expected that this output the h3 title and then the title of the post marked featured.
In the end, I would like it to function much like latest post previews, but display custom fields and only if the 'featured' true/false is set to yes
I have made an ACF field called 'featured yachts' and registered the block with Gutenberg, but there are no actual ACF fields within it, it's only used to call the file 'content-featured-yachts-block.php' which has this code I am trying to fix.
I am trying to populate the post previews within this featured yachts block with data pulled from the individual yacht listings. In these listings is the 'featured' true/false option. Screen shot atttached.
This is my code for registering the CPT
// Our custom post type function
function create_posttype() {
register_post_type( 'yachts',
// CPT Options
array(
'labels' => array(
'name' => __( 'Yacht Listings' ),
'singular_name' => __( 'Yacht' ),
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
'add_new' => __( 'New Yacht Listing'),
'add_new_item' => __( 'Add New Yacht Listing'),
'edit_item' => __( 'Edit Yacht Listing'),
'new_item' => __( 'New Yacht Listing'),
'view_item' => __( 'View Listings'),
'search_items' => __( 'Search Listings'),
'not_found' => __( 'No Yacht Listings Found'),
'not_found_in_trash' => __( 'No yacht Listings found in Trash')
),
'public' => true,
// 'has_archive' => true,
'rewrite' => array('slug' => 'yachts'),
'show_in_rest' => true,
'menu_icon' => 'dashicons-sos',
'hierarchical' => true,
'taxonomies' => array('category')
)
);
}
Another edit - I made the assumption that if I could get the title field to show, the other fields would be easy but i can't get them either so I ALSO need to work out how to add the additional fields from the listing
The code I have tried is below
<h2>FEATURED YACHTS</h2>
<?php
$args = array(
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'featured',
'value' => 'yes',
'compare' => 'LIKE',
)
),
);
$my_posts = new WP_Query($args);
if ($my_posts->have_posts()) {
while ($my_posts->have_posts()) : $my_posts->the_post();?>
<h2><?php the_title(); ?></h2>
<?php
get_post_meta( get_the_ID(), 'price', true );
?>
<?php endwhile;
wp_reset_postdata();
}
?>
AND ALSO
<section class="featured-yachts">
<h2>FEATURED YACHTS</h2>
<?php
$args = array(
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'featured',
'value' => 'yes',
'compare' => 'LIKE',
)
),
);
$my_posts = new WP_Query($args);
if ($my_posts->have_posts()) {
while ($my_posts->have_posts()) : $my_posts->the_post();?>
<h2><?php the_title(); ?></h2>
<p><?php the_field( 'price' ); ?></p>
<?php endwhile;
wp_reset_postdata();
}
?>
</section>
You can use 'meta_query' and for ACF true and false you don't have to compare with LIKE. Try the below code.
<section class="featured-yachts">
<h2>FEATURED YACHTS</h2>
<?php
$args = array(
'post_type' => 'yachts',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'featuredyacht',
'value' => '1',
)
),
);
$my_posts = new WP_Query($args);
if ( $my_posts->have_posts() ) {
while ( $my_posts->have_posts() ) : $my_posts->the_post();
echo "Title - ".get_the_title()."</br>";
echo "Price - ".get_field( "price", get_the_ID() )."</br>";
echo "Length - ".get_field( "length", get_the_ID() )."</br>";
echo "Year built - ".get_field( "year_built", get_the_ID() )."</br>";
echo "Capacity - ".get_field( "capacity", get_the_ID() )."</br>";
endwhile;
wp_reset_postdata();
}
?>
</section>
To use multiple custom field parameters in your query, replace $args as in Bhautik's answer with something like this:
$args = array(
'post_type' => 'yachts',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'featuredyacht',
'value' => '1',
),
array(
'key' => 'price',
'value' => 50000,
'type' => 'numeric',
'compare' => '>=',
)
),
);
The above example fetches only yachts with featuredyacht set to 1 or true AND with a price of 50,000 or more. Adjust as needed to suit your parameters.
For example, to query featured yachts within a specific price range:
$args = array(
'post_type' => 'yachts',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'featuredyacht',
'value' => '1',
),
array(
'key' => 'price',
'value' => array( 50000, 100000 ),
'type' => 'numeric',
'compare' => 'BETWEEN',
)
),
);
The developer documentation on WP_Query should be very useful to you for any further customizations.
I'm having a hard time accomplishing two things. I've created a custom post type for Events. I would like for the client to be able to post the event by the date. This means publishing posts that are scheduled for the future to appear published. I would also like the posts to revert back to drafts once the date has passed. Anyone know how to accomplish this? Here's the code I've been toying with:
<?php
// Register Custom Post Type: Events Posts
add_action('init', 'events_register');
function events_register() {
$labels = array(
'name' => _x('Events', 'post type general name'),
'singular_name' => _x('Event', 'post type singular name'),
'add_new' => _x('Add New', 'Event item'),
'add_new_item' => __('Add New Event'),
'edit_item' => __('Edit Event'),
'new_item' => __('New Event'),
'view_item' => __('View Event Item'),
'search_items' => __('Search Events'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => 'dashicons-calendar-alt',
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 4,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'events' , $args );
function setup_future_hook() {
// Replace native future_post function with replacement
remove_action('future_events','_future_post_hook');
add_action('future_events','publish_future_post_now');
}
function publish_future_post_now($id) {
// Set new post's post_status to "publish" rather than "future."
wp_publish_post($id);
}
add_action('init', 'setup_future_hook');
}
This is my loop:
<?php // WP_Query arguments
$args = array (
'post_type' => array( 'events' ),
'order' => 'ASC',
'posts_per_page' => '4',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post(); ?>
<div class="col-md-6">
<div class="event-box">
<h4><?php the_title(); ?></h4>
<h5><?php the_field('venue_name'); ?></h5>
<div class="date"><?php the_date( 'F j, Y' ); ?></div>
<div class="time"><?php the_field('event_time'); ?></div>
<div class="row">
<div class="col-6">
<a target="_blank" class="btn btn-primary" href="<?php the_field('buy_tickets_link'); ?>">Buy Tickets</a>
</div>
<div class="col-6">
<a target="_blank" class="btn btn-primary" href="<?php the_field('venue_link'); ?>">Venue Info</a>
</div>
</div>
</div>
</div>
<?php }
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata(); ?>
Thanks!!
$args = array (
'post_type' => array( 'events' ),
'order' => 'ASC',
'posts_per_page' => '4',
'post_status' => array('publish', 'future'),
);
Try adding 'post_status' => array('publish', 'future') in your argument. Let me know if this worked or not.
If you only want to display future posts, try changing your WP_Query arguments to this:
$args = array (
'post_type' => 'events',
'order' => 'ASC',
'posts_per_page' => '4',
'post_status' => 'future',
);
Also, you might want to consider using an events plugin for this functionality; like The Events Calendar.
I have created a custom post type (school) and a custom taxonomy (region) attached to it.
Everything works great except I want to create a shortcode that only get the school that belongs to a specific entry in that custom taxonomy.
That means when you will write the shortcode you will pass a region name, and only schools that belong to that region will return from the database.
I managed to use the shortcode, but not to filter according to the region.
This is my custon taxonomy:
$taxonomies['regions'] = array(
'hierarchical' => true,
'query_var' => 'school_region',
'rewrite' => array(
'slug' => 'schools/region'
),
'labels' => array(
'name' => __('Region'),
'singular_name' => __('Region'),
'add_new' => __('Add New Region'),
'add_new_item' => __('Add New Region'),
'edit_item' => __('Edit Region'),
'new_item' => __('Add New Region'),
'view_item' => __('View Region'),
'search_items' => __('Search Regions'),
'not_found' => __('No Region Found'),
'not_found_in_trash' => __('No Regions Found In Trash'),
),
);
And this is my shortcode:
add_shortcode('rs_school',function($atts, $content=null){
$loop = new WP_Query( array(
'post_type' => 'rs-school',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
) );
//var_dump($loop);
if($loop->have_posts() ){ ?>
<ul class="related">
<?php
while ($loop->have_posts()) {
$loop->the_post();
//$meta = get_post_meta(get_the_ID(), '');
$terms = get_the_terms( $post->ID , 'regions' );
var_dump($terms);
if (in_array($theregion, $terms)){
?>
<li>
<?php echo get_the_title() ?>
</li>
<?php
}
} ?>
</ul>
<div class="clearfix"></div>
<?php
}
});
How can I do that?
best regards
so managed to work it out. so hopefully will help others:
i send the term id to the short code, and use it to fillter it:
$atts = shortcode_atts(
array(
'region' => 15,
), $atts, 'rs_school' );
and then filter it like so:
$loop = new WP_Query( array(
'post_type' => 'rs-school',
'posts_per_page' => -1,
'orderby' => 'date', // Purely optional - just for some ordering
'order' => 'DESC', // Ditto
'tax_query' => array(
array(
'taxonomy' => 'regions', //or tag or custom taxonomy
'field' => 'id',
'terms' => $atts['region']
)
)
) );
hope it will help others.
I'm using:
Wordpress 3.4
WP-PageNavi 2.82
I register custom taxonomy (catalog)
<?php
add_action('init', 'pca_register_taxonomy', 0);
function pca_register_taxonomy()
{
register_taxonomy('catalog', null,
array(
'label' => __('Catalogs', __),
'labels' => array(
'name' => __('Catalogs', __),
'singular_name' => __('Catalog', __),
'search_items' => __('Search Catalogs', __),
'popular_items' => __('Popular Catalogs', __),
'all_items' => __('All Catalogs', __),
'parent_item' => __('Parent Catalog', __),
'parent_item_colon' => __('Parent Catalog', __),
'edit_item' => __('Edit Catalog', __),
'update_item' => __('Update Catalog', __),
'add_new_item' => __('Add New Catalog', __),
'new_item_name' => __('New Catalog Name', __),
'separate_items_with_commas' => __('Separate catalogs with commas', __),
'add_or_remove_items' => __('Add or remove catalogs', __),
'choose_from_most_used' => __('Choose from the most used catalogs', __),
'menu_name' => __('Catalogs', __)
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'catalog',
'with_front' => true,
'hierarchical' => true
),
'capabilities' => array(
'manage_terms',
'edit_terms',
'delete_terms',
'assign_terms'
)
)
);
}
?>
I register custom post type (product)
<?php
add_action('init', 'pca_register_post_type');
function pca_register_post_type()
{
register_post_type('product',
array(
'label' => __('Products', __),
'labels' => array(
'name' => __('Products', __),
'singular_name' => __('Product', __),
'add_new' => __('Add New', __),
'add_new_item' => __('Add New Product', __),
'edit_item' => __('Edit Product', __),
'new_item' => __('New Product', __),
'all_items' => __('All Products', __),
'view_item' => __('View Product', __),
'search_items' => __('Search Products', __),
'not_found' => __('No products found', __),
'not_found_in_trash' => __('No products found in Trash', __),
'parent_item_colon' => '',
'menu_name' => __('Products', __)
),
'description' => '',
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 20,
'capability_type' => 'post',
'meta_cap' => true,
'hierarchical' => false,
'supports' => array(
'title',
'editor',
'thumbnail',
'page-attributes',
'post-formats'
),
'taxonomies' => array('catalog'),
'has_archive' => false,
'rewrite' => array(
'slug' => 'products',
'with_front' => true,
'feeds' => false,
'pages' => true
),
'query_var' => true,
'can_export' => true
)
);
}
?>
Then I create a new file for tax -> taxonomy-catalog.php
In this file, I query all products (custom post type) from specified catalog (tax):
<?php
$paged = get_query_var('paged');
$paged = ($paged) ? $paged : 1;
$products = new WP_Query(array(
'catalog' => $catalog_data->slug, // $catalog_data is the current taxonomy (woman)
'post_type' => 'product',
'posts_per_page' => 12,
'paged' => $paged
));
?>
<?php while ($products->have_posts()) : $products->the_post(); ?>
// Show title, content ... everything ok
<?php endwhile; ?>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $products)); ?>
<?php wp_reset_postdata(); ?>
Pagination is displayed correctly but when I click on page 2 or over I have a 404 error.
Works -> mywebsite.com/catalog/woman
Works not -> mywebsite.com/catalog/woman/page/2
I already refreshed permalinks.
Any idea to fix this ? thanks
Put this into your "functions.php" and then regenerate permalinks.
It works to me!
function taxonomy_rewrite_fix($wp_rewrite) {
$r = array();
foreach($wp_rewrite->rules as $k=>$v){
$r[$k] = str_replace('catalog=$matches[1]&paged=','catalog=$matches[1]&page=',$v);
}
$wp_rewrite->rules = $r;
}
add_filter('generate_rewrite_rules', 'taxonomy_rewrite_fix');
The key is to replace "paged" to "page" into the rewrite rule for your custom taxonomy.
This is my first contribution here. Hope I help you.
Once I have faced problem about this and passed hard times hrs to hrs by pulling hair. I googled and didn't found any specific solution about the topics. I found several talents' article but they weren't satisfying my problems. Actually custom taxonomy archive page pagination is depends on some settings of arguments of related functions. So I am actually going here sharing my thoughts of solving the taxonomy archive pagination problem.
Five things you need for custom taxonomy archive page pagination working perfectly :
( 1 ) Don't put exclude_from_search parameter key as register_post_type argument parameter or
if mention set it 'exclude_from_search' => false. By default it is set false if not mentioned.
( 2 ) The taxonomy that will be use with the custom post type set
'taxonomies' => 'custom_taxonomy_name' as register_post_type argument parameter or
use register_taxonomy_for_object_type() directly.
Custom taxonomies still need to be registered with register_taxonomy().
( 3 ) While querying within new WP_Query ($args)
i ) If not set in admin `static front page` use before `new WP_Query($args)`
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
and use $query = new WP_Query( array( 'paged' => $paged ) );
ii ) If set in admin static front page use before 'new WP_Query($args)'
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
and use $query = new WP_Query( array( 'page' => $paged ) );
Remember to use posts_per_page and paged parameter in new WP_Query($arg) argument array.
If not set static front page then you should use page parameter in new WP_Query ($arg) argument array
( 4 ) Use Wordpress paginate_links( $args ) function like the example below to render pagination in archive template file.
<?php $big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%', or '/paged=%#%', // if using pretty permalink
'current' => max( 1, get_query_var('paged') ),
'total' => $query->max_num_pages ) ); // Here $max_num_pages is the properties of new WP_Query() object . It is total number of pages. Is the result of $found_posts / $posts_per_page
?>
( 5 ) The paginate_links() function output the ul li listing with page-numbers class.
If you use bootstrap inject pagination class to the ul with the help of javascript or jquery and a nice fancy pagination will be output.
Hope you can now enjoy pagination in the taxonomy archive template without any 404 problem :-)
What helped me is to set "Blog pages show at most" in Reading Settings to 1. Then it works.
With the default 10, it throws 404 error on page 2. On page 1 it's all perfect.
So given this works, the solution is to set "Blog pages show at most" to 1 only for those taxonomies or categories you need. The code you should place inside functions.php is here: https://forums.envato.com/t/wordpress-custom-page-type-taxonomy-pagination/76549/12
Basically that's
get_query_var('page')
that holds the page number
from the working code:
global $query_string;
$page_index = max(1, get_query_var('page'));
parse_str($query_string, $queryParams);
$queryParams['paged'] = $page_index;
$queryParams['posts_per_page'] = $posts_per_page;
query_posts($queryParams);
Use query_posts instead of wp_query. It should work.
This is my Code.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'paged' => $paged,
'orderby' => 'asc',
'tax_query' => array(
array(
'taxonomy' => "$term->taxonomy",
'terms' => "$term->name",
'field' => 'slug'
)
)
);
$query = new WP_Query( $args );
if($query->have_posts() ) :
// your code
?>
<?php endwhile; endif;
wp_pagenavi();?>
When you create any CPT then you need to add this function.flush_rewrite_rules();It will manage/adjust/reassign your memory.So please add this line your code will work.Precaution.1: Add this function : flush_rewrite_rules();2:Your pagination function (wp_pagenavi()) will call just below the endwhile;I 'm sure,your pagination will work and let me know if it will not work.
Thanking you.