Pagination on "get_term_children" - Wordpress - php

I would like to get a pager in my page, can i create a pager with a for each or while without parameter like "posts_per_page" ?
I get term children of my taxonomy and i would like to display 3 by 3
My code :
$childGalerie = get_term_children(15,'wpmf-category');
foreach ( $childGalerie as $oneGalerie ) :
$maGalerie = get_term($oneGalerie, 'wpmf-category');
?>
<h2 class="info-galerie"><span></span><?php echo $maGalerie->name; > </h2>
<div class="galerie-photo">
<?php
global $post;
$args = array(
'posts_per_page' => -1,
'post_type' => 'attachment',
// 'post_status' => 'inherit',
'tax_query' => array(
array(
'taxonomy' => 'wpmf-category',
'field' => 'term_id',
'terms' => $oneGalerie
),
),
);
$media = get_posts( $args );
foreach ( $media as $post ) : setup_postdata( $post );
?>
<div class="wrapper-galerie">
<?php echo wp_get_attachment_image( $media->ID, 'galerie->photo' ); ?>
</div>
<?php
endforeach;
wp_reset_postdata();
?>
</div>
<?php
endforeach;
Can you help me please , ty :D

Related

ACF not showing below products

I can't seem to work out why my ACF fields will not display below my woo-commerce products on the featured page when they display fine above them?
Products
<div id="post-load" class="row products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'nopaging' => true,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product; ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; ?>
</div>
ACF Example (This works fine if placed above the products)
<?php
$features = get_field('features');
if( $features ): ?>
<div class="col-md-12"><h3 class="txtc"><?php echo esc_html( $features['title'] ); ?></h3></div>
<?php endif; ?>

Group by a custom value field wordpress posts

I have several posts with a custom field named "series". I want to group all posts by this custom field and below of this i want to list all posts which have not this custom field.
First i wanted to get grouped custom field value and then to be able to query again for all posts with this custom value key and value. But even trying to get the unique custom values does not work.
What i tried is this:
<?php
function query_group_by_filter($groupby){
global $wpdb;
return $wpdb->postmeta . '.meta_key = "series"';
}
?>
<?php add_filter('posts_groupby', 'query_group_by_filter'); ?>
<?php $states = new WP_Query(array(
'meta_key' => 'series',
'ignore_sticky_posts' => 1
));
?>
<?php remove_filter('posts_groupby', 'query_group_by_filter'); ?>
<ul>
<?php
while ( $states->have_posts() ) : $states->the_post();
$mykey_values = get_post_custom_values( 'series' );
foreach ( $mykey_values as $key => $value ) {
echo "<li>$key => $value ( 'series' )</li>";
}
endwhile;
?>
</ul>
Whats wrong with this code?
WP_Meta_Query
All posts with custom value:
<?php
$args = array(
'post_type' => 'my-post-type',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'series',
'value' => 'my-val',
'compare' => '='
),
array(
'key' => 'series',
'value' => '',
'compare' => '!='
)
)
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</li>
<?php
endwhile;
wp_reset_postdata(); ?>
</ul>
<?php endif; ?>
And without values:
<?php
$args = array(
'post_type' => 'my-post-type',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'series',
'value' => '',
'compare' => '='
)
)
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</li>
<?php
endwhile;
wp_reset_postdata(); ?>
</ul>
<?php endif; ?>

Excluding a Taxonomy From Post Type Loop Separated by Categories

I'm trying to display a post type’s categories and output the posts within that category, but I have another taxonomy that I want to exclude. This code is showing all Taxonomies and Terms registered to the specific post type.
The second taxonomy that I am trying to exclude is named "manufacturer" and is registered to multiple post types. I have tried doing 'operator'=>'NOT EXISTS' as well as what you see below, with the if...continue but nothing seems to work !!
<?php
$post_type = 'equipment';
$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
$terms = get_terms( $taxonomy );
foreach( $terms as $term ):
if ( $term->slug == 'manufacturer' )
continue;
?>
<div class="row">
<div class="col-xs-12">
<h2><?php echo $term->name; ?></h2>
</div>
<div class="col-xs-12">
<?php
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term->slug,
)
)
);
$posts = new WP_Query($args);
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>
<h4><?php echo get_the_title(); ?></h4>
<?php endwhile; endif; ?>
</div>
</div>
<?php endforeach;
endforeach; ?>
)
$args = array(
'post_type' => array('equipment'),
'posts_per_page' => -1,
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'manufacturer',
'field' => 'slug',
'operator' => 'NOT IN',
),
),
);
$query = new WP_Query( $args );

How to get taxonomy post link and display

I had created this loop for getting the last added taxonomy category posts.Here is the code
$issue = get_terms('articles-tax','orderby=Desc&order=ASC');
$latest_edition = $issue[0]->slug;
$latest_edition = $issue[0]->term_id;
$postsart = get_posts(array(
'showposts' => -1,
'post_type' => 'articles',
'tax_query' => array(
array(
'taxonomy' => 'articles-tax',
'field' => 'term_id',
'terms' => $latest_edition)
)) ); foreach ($postsart as $mypost) { ?>
<div class="article_item"><div class="article_title"><?php echo $mypost->post_title?></div><div class="article_short_content"> <?php echo $mypost->post_excerpt ?> </div>
<div class="news_border"></div>
<div class="news_readmore">Read More</div>
</div>
So Now I cant get the permalink of the post, didnt know how to get from the array.Had done var_dump of $mypost, but cant manage how to get one item permalink.Help me to fix this pls!
use
$permalink = get_permalink($mypost->ID);
echo $permalink ;
It will give you posts' permalink
Adding "global post" function to the code seems to do the trick
like this:
$postsart = get_posts(array(
'showposts' => -1,
'post_type' => 'articles',
'tax_query' => array(
array(
'taxonomy' => 'articles-tax',
'field' => 'term_id',
'terms' => $latest_edition)
)) );
global $post;
foreach ($postsart as $post) {
setup_postdata($post);
?>
<div class="article_item"><div class="article_title"><?php echo $post->post_title?></div><div class="article_short_content"> <?php echo $post->post_excerpt ?> </div>
<div class="news_border"></div>
<div class="news_readmore">Read More</div>
</div>

exclude a custom taxonomy from wp_query

IN my wp site, I have 2 category and a few post like that..
cat_1- post 1, post 2, post 3.
cat_2- post 2, post 3, post 4.
When i am in post 3 page, i want to show releted article only from category 2.here is my code:but it returns empty. Probably i did not catch the logic. Any help would be highly appreciated.
<?php
$terms = get_the_terms( $post_id, 'category' );
if( empty( $terms ) ) $terms = array();
$term_list = wp_list_pluck( $terms, 'slug' );
$related_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'post__not_in' => array( get_the_ID() ),
'orderby' => 'desc',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $term_list
),
array(
'taxonomy' => 'category',
'terms' => array('cat_1'),
'field' => 'slug',
'operator' => 'NOT IN',
),
),
);
$related = new WP_Query( $related_args );
if( $related->have_posts() ):
?>
<div class="post-navigation">
<h3>Related posts</h3>
<ul>
<?php while( $related->have_posts() ): $related->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
</div>
<?php
endif;
wp_reset_postdata();
?>
here is the following query ...may be helpful to you...
$custom_tex=array(array('taxonomy'=>'category','field'=>'slug','terms'=>'cat_2'));
$new = new WP_Query(array('post_type'=>'post','posts_per_page'=>-1, 'tax_query'=>$custom_tex,'order' => 'DESC','orderby' => 'ID' ));
while ($new->have_posts()) : $new->the_post();
echo $post->post_title;
echo "<br>";
endwhile;

Categories