I have made the visual composer addon to meet one of the requirement. However I have found that it always come above the other vc elements.
I have tried to add the class as per vc composer other elements
public function sim_product($attr)
{
?>
<div class="vc_column-inner"><div class="wpb_wrapper">
<div class="wpb_text_column wpb_content_element ">
<div class="wpb_wrapper">
<div class="more-project-list">
<?php
$select = $attr['sim_product_id'];
$query = new WP_Query( array( 'post_type' => 'products','post__in' => explode(",",$select) ));
if ( $query->have_posts() ) { ?>
<?php while ( $query->have_posts() )
{ $query->the_post(); ?>
<div class="single-blk" style='background-color: <?php echo the_field('colour');?>'>
<div class="title">
<?php the_title();?>
</div>
<figure>
<?php if (has_post_thumbnail( $query->ID ) )
{
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $query->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" alt="">
<?php }?>
</figure>
<div class="category">
<?php
$terms = wp_get_post_terms( $query->post->ID, array( 'Product_category') );
foreach ( $terms as $term ) { echo $term->name;}
?>
</div>
</div>
<?php }}?>
</div>
</div></div></div></div>
<?php
}
It isnt coming where I have placed it it always come on top
Related
i try to get posts via query wordpress
i need to fetch the posts thats's in spacfic taxonamy
تصميم تطبيقات
<?php
get_query_var('taxonomy');
$taxonomy = 'eposd_category';
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) :
?>
<?php foreach ( $terms as $term ) { ?>
<div class="col-sm-3">
<div class="item">
<div class="load">
<?php echo z_taxonomy_image($lug term->term_s); ?>
<div class="load-icon text-center">
<i class="fa fa-play"></i>
</div>
</div>
<div class="item-content">
<h2><?php echo $term->name; ?></h2>
</div>
</div>
</div>
<?php } ?>
<?php endif;?>
تصميم العاب
I'm trying to list the posts related to the current taxonomy page but it shows me all the posts instead. When I output the current term name is correct so really I don't know why this happens. I'm pasting here the code if anyone can put me in the right direction.
<?php
$term = get_queried_object();
// Define the query
$args1 = array(
'post_type' => 'properties-for-sale',
'taxonomy' => $term->term_id
);
$query = new WP_Query($args1);
if ($query->have_posts()) { ?>
<h2 class="region-listing-title"><span class="thin-span">Luxury Properties for sale in</span> <?php echo $term->name; ?></h2>
<div class="swiper myswiper swiper-h">
<div class="swiper-wrapper">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="swiper-slide">
<div class="favorite-button"><?php the_favorites_button($post_id, $site_id); ?></div>
<div class="swiper myswiper2 swiper-v">
<div class="swiper-wrapper">
<?php
$images = get_field('listing_gallery');
if ($images) : ?>
<?php foreach ($images as $image) : ?>
<div class="swiper-slide highlight-img" style="background-image: url(<?php echo $image['url']; ?>)"></div>
<?php endforeach; ?>
<?php endif;
?>
</div>
<div class="swiper-pagination"></div>
</div>
<div class="listing-informations">
<div id="lp-region-sale" class="listing-information-price">
<span><?php the_field('property_price'); ?> €</span>
</div>
<div>
<?php the_title(); ?>
</div>
<div class="listing-informations__listing-details">
<div class="listing-information-label"><span></span><?php the_field('number_of_bedrooms'); ?> Beds</div>
<div class="listing-information-label"><span></span><?php the_field('number_of_bathrooms'); ?> Baths</div>
<div class="listing-information-label"><span></span><?php the_field('interior_square_meters'); ?> Int Sqm</div>
<div class="listing-information-label"><span></span><?php the_field('lot_square_meters'); ?> Lot Sqm</div>
</div>
</div>
</div>
<?php endwhile;
} ?>
</div>
</div>
<?php wp_reset_postdata();
?>
Try with:
<?php
$term = get_queried_object()->term_id;
// Define the query
$args1 = array(
'post_type' => 'properties-for-sale',
'taxonomy' => $term
);
$query = new WP_Query($args1);
if ($query->have_posts()) { ?>
<h2 class="region-listing-title"><span class="thin-span">Luxury Properties for sale in</span> <?php echo $term->name; ?></h2>
<div class="swiper myswiper swiper-h">
<div class="swiper-wrapper">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="swiper-slide">
<div class="favorite-button"><?php the_favorites_button($post_id, $site_id); ?></div>
<div class="swiper myswiper2 swiper-v">
<div class="swiper-wrapper">
<?php
$images = get_field('listing_gallery');
if ($images) : ?>
<?php foreach ($images as $image) : ?>
<div class="swiper-slide highlight-img" style="background-image: url(<?php echo $image['url']; ?>)"></div>
<?php endforeach; ?>
<?php endif;
?>
</div>
<div class="swiper-pagination"></div>
</div>
<div class="listing-informations">
<div id="lp-region-sale" class="listing-information-price">
<span><?php the_field('property_price'); ?> €</span>
</div>
<div>
<?php the_title(); ?>
</div>
<div class="listing-informations__listing-details">
<div class="listing-information-label"><span></span><?php the_field('number_of_bedrooms'); ?> Beds</div>
<div class="listing-information-label"><span></span><?php the_field('number_of_bathrooms'); ?> Baths</div>
<div class="listing-information-label"><span></span><?php the_field('interior_square_meters'); ?> Int Sqm</div>
<div class="listing-information-label"><span></span><?php the_field('lot_square_meters'); ?> Lot Sqm</div>
</div>
</div>
</div>
<?php endwhile;
} ?>
</div>
</div>
<?php wp_reset_postdata();
?>
Just use tax query.
<?php
$term = get_queried_object()->term_id;
$args = array(
'post_type' => 'properties-for-sale',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'term_id',
'terms' => $term->term_id
)
)
);
$query = new WP_Query( $args ); ?>
I am trying to query Wordpress custom posts and categories they are related to.
Query acts strangely, displays category name and all customs posts, not even related to that category (keeps repeating till all categorie names are displayed.)
Example image : Wordpress custom query display
My query code:
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="lookbook-header">
<div class="wrap">
<p class="text-left">lookbook</p>
</div>
</div>
<?php
$taxonomy = 'lookbook_categories';
$terms = get_terms($taxonomy);
$args=array(
'taxonomy' => 'lookbook_categories'
'post_type' => 'lookbook',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if ( $terms && !is_wp_error( $terms ) ) :
foreach ( $terms as $term ) { ?>
<div class="lookbook-category">
<p class="text-center">
<?php echo $term->name; ?>
</p>
</div>
<?php
if( $my_query->have_posts() ) {
echo '';
$count=0;
while ($my_query->have_posts()) : $my_query->the_post();
if($count == 3) {?>
<div class="row">
<?php }
?>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 no-padding">
<div class="lookbook-item">
<div class="hvrbox">
<?php
$image = get_field('lookbook_image');
if( !empty($image) ): ?> <img src="<?php echo $image['url']; ?>" alt="news" class="img-responsive" />
<?php endif; ?>
<div class="hvrbox-layer_top">
<div class="hvrbox-text">
<div class="separator"></div>
<h3><?php the_title();?></h3>
<div class="separator"></div>
<p>
<?php the_field('excerpt');?>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
$count++;
if($count == 3) echo '</div>';
endwhile;
}
}
endif;
wp_reset_query();
?>
</div>
</div>
I would like to display category name + posts related to category (not all posts over and over again)
You want to pass in an array to get_terms like:
$terms = get_terms( array(
'taxonomy' => 'lookbook_categories',
'hide_empty' => false,
) );
you can read more about it here: https://developer.wordpress.org/reference/functions/get_terms/
I created a Shortcode slider which gets ids of different pages and show display slider. Shordcode works fine but issue is that whenever i am copy past shortcode multiple times on same page/ template page it shows only first one.
This issue occurs only only when i past same type of shortcode but if i past any other shortcode on same page it works fine.
Here is my code
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is shortcode
[objectx-pages-list id="15,16,17"]
[objectx-pages-list ids="25,26,27"]
here you can see live example
http://objextheme.wpengine.com/
This one working fine
ROOFTOP PATIO & LOUNGE
but this is not working
This Week At Vertigo Sky Lounge
Please guide me where i am doing mistake. Thanks
add_shortcode( 'objectx-pages-list', 'objectx_pages_list_func' );
function objectx_pages_list_func( $atts ) {
global $post;
ob_start();
extract( shortcode_atts( array('ids' => '1186'), $atts ) );
$id_array = explode(',', $ids);
$pages_query = new WP_Query( array(
'post_type' => 'page',
'post__in' => $id_array,
'order' => 'ASC',
'orderby' => 'title',
) );
if ( $pages_query->have_posts() ) { ?>
<div class="carousel-wrapper">
<div class="owl-carousel owl-theme carousel-1" id="carousel-rooms">
<?php while ( $pages_query->have_posts() ) : $pages_query->the_post();
$featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div <?php post_class('item'); ?> id="post-<?php the_ID(); ?>">
<div class="row">
<div class="col-md-7">
<div class="img-rooms">
<a href="<?php the_permalink(); ?>">
<img class="img-responsive wp-post-image" src="<?php echo $featured_image; ?>"></a>
</div>
</div>
<div class="col-md-5">
<div class="detail-rooms">
<h2 class="title-room "><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php $myvariable_pages = ob_get_clean();
wp_reset_postdata();
return $myvariable_pages;
}
}
Here is the error i noticed. id="carousel-rooms" Id repeating on
same page. that is why only one time it runs perfect.
i have a problem with search result page, the pagination doesn't works, when i want to go to next page, i'm redirected to index page, but the url is: www.mywebsite.com/page/2/?s=word..
For all pages the pagination works, only for search doesn't works.
this is the code of search.php
<?php
/**
* The template for displaying Search Results pages.
*/
get_header(); ?>
<?php
$search = isset( $_GET['s'] ) ? $_GET['s']: null;
$user_filtre = '';
$user_display = '';
if( $search ){
$user_filtre .= 's=' . $_GET['s'] . '&';
$user_display .= 's=' . $_GET['s'] . '&';
}?>
<div id="main-search" class="content-dark hidden-sm hidden-xs">
<div class="container">
<form method="get" action="<?php bloginfo('url'); ?>" accept-charset="UTF-8">
<!--input name="s" id="s" type="hidden" -->
<div id="main-search-fields">
<p class="pull-left term">Search Term:</p>
<input name="s" value="<?php the_search_query(); ?>"autocomplete="off" type="search">
</div>
<div id="main-search-btn">
<input class="button-green-download-big" type="submit" value="Search">
</div>
</form>
</div>
</div>
<div class="browse-content">
<div class="container">
<section>
<div class="row">
<ul>
<?php if(have_posts() ): ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php include '_includes/items/item_2.php';?>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
</section>
<?php novavideo_theme_pagination(); ?>
</div>
</div>
</div>
Anyone have an ideea?
item_2.php.
<div class="browse-movie-wrap col-xs-10 col-sm-4 col-md-5 col-lg-4">
<a href="<?php the_permalink(); ?>" class="browse-movie-link">
<figure>
<?php if($values = get_post_custom_values("poster_url")) { ?>
<img class="img-responsive" src="<?php echo $values[0]; ?>" alt="<?php the_title();?> Watch Online" width="210" height="315">
<?php } ?>
<figcaption class="hidden-xs hidden-sm">
<span class="fa fa-star icon-color"></span>
<h4 class="rating"><?php $rating = get_post_custom_values("imdbRating"); echo $rating[0]; ?> / 10</h4>
<h4>
<?php $categories = get_the_category();
if ( ! empty( $categories[0] ) ) {
echo esc_html( $categories[0]->name );
}
?>
</h4>
<h4 class="quality-button"><span class="fa fa-play-circle"></span> <?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'quality', '', ', ', '' ) ); echo $terms_as_text;; ?></h4>
<span class="button-green-download-big margin-button">Open Movie</span>
</figcaption>
</figure>
</a>
<div class="browse-movie-bottom">
<?php $title = get_post_custom_values("Title"); echo $title[0]; ?>
<div class="browse-movie-year"><?php $terms = wp_get_post_terms($post->ID, 'release-year', array("fields" => "all")); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term_single ) { $term_link = get_term_link( $term_single ); echo $term_single->name; } } ?></div>
</div>
</div>
Search results are instantiated through query_posts and that controls how many results you have per page. In your code, it's probably happening via the include: /_includes/search-template.php but if not, set it up like this:
// 1- Created a paged variable that knows how many paginated pages exist (depends on your site)
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// 2- Pass `paged` into array of arguments for query_posts
$args = array(
'posts_per_page' => 20,
'order' => 'DESC',
'paged' => $paged,
);
// 3- Submit query_posts to WordPress with arguments set
query_posts( $args );
Now you can use next_posts_link(); to show the paginated page link. Just replace the references to theme_pagination(); with next_post_link(); and it should output the right results.
If you want to abstract all this logic out of your template, check out pre_get_posts. It's a different method and you would put all this logic into functions.php but will achieve similar results.
This is my code for Search result page with pagination:
<?php get_header(); ?>
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/search.css">
<?php wp_head(); ?>
<script type="text/javascript">
var window_width = window.screen.width;
var window_height = window.screen.height;
<?php $window_width = "<script>document.write(window_width)</script>";
$window_height = "<script>document.write(window_height)</script>"; ?>
</script>
<style>
.sm_bd{padding: 5px;
border: 1px solid
#ccc;}
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
.previous,.next {
padding: 5px;
border: 1px solid
#ccc;
border-radius: 4px;
margin: 15px;
}
</style>
</head>
<body class="index-body">
<?php include 'menu.php';?>
<div class="col-xs-12 col-sm-12 blog-page no-marg no-padd">
<div class="col-xs-4 col-sm-3 single-sidebar no-marg no-padd">
My sidebar
</div>
<section id="primary" class="content-area col-xs-12 col-sm-12 col-lg-8 col-md-8">
<div id="content" class="site-content row" role="main">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1';
$s=get_search_query();
$args = array(
's' =>$s,
'paged' => $paged,
'posts_per_page' => '12',
);
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
_e("<h2 style='font-weight:bold;color:#000'>نتایج جستجو برای: ".get_query_var('s')."</h2>");
echo "<div class='col-lg-12 col-md-12'><hr/></div>";
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<div class="col-xs-12 col-sm-12 col-lg-3 col-md-3 sm_bd">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php else : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<img class="attachment-post-thumbnail size-post-thumbnail wp-post-image lazyloaded" src="Without Image"
alt="<?php the_title_attribute(); ?>"
title="<?php the_title_attribute(); ?>" width="300" height="449">
</a>
<?php endif;?>
<?php the_title(); ?>
</div>
<?php
}
?>
<div class="pagination" id="blog-pagination">
<?php if( get_previous_posts_link('← ', $loop->max_num_pages ) ) : ?>
<span class="previous" ><?php previous_posts_link( '→ ', $loop->max_num_pages ); ?></span>
<?php endif; ?>
<?php if( get_next_posts_link('← ', $loop->max_num_pages ) ) : ?>
<span class="next"><?php next_posts_link( '←', $loop->max_num_pages ); ?></span>
<?php endif; ?>
</div>
<?php
}
else{
?>
<h2 style='font-weight:bold;color:#000'>not found title</h2>
<div class="alert alert-info">
<p>not found alert</p>
</div>
<?php }
wp_reset_postdata();?>
</div><!-- #content .site-content -->
</section><!-- #primary .content-area -->
</div>
<?php get_footer(); ?>
don't forget to write wp_reset_postdata(); after post loop.