最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Create a navbar filter that filters by a custom field

programmeradmin4浏览0评论

My widget displays all the articles that have been included in the portfolio. I need to create a navbar on which I would insert buttons that will filter based on the selected category.

This is my code:

    <div class="row portfolio-group">
  <?php
  $args = array(
    'post_type' => 'post',
    'orderby' => 'date',
    'order'   => 'DESC', //ASC crescente
    'posts_per_page' => '5',//NUM post visualizzati
    'meta_query' => array(
      array(
        'key' => 'in_portfolio',
        'value' => '1'
      ),
    ),

  );
  $post_query = new WP_Query($args);
  if($post_query->have_posts() ) {
    while($post_query->have_posts() ) {
      $post_query->the_post();

      ?>

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<div class="blog-card">
<div class="meta">
<div class="photo" style="background-image: url(<?php echo $url ?>)"></div>
<ul class="details">
  <li class="author"><a href="#">Name Surname</a></li>
</ul>
</div>
<div class="description">
<h1><?php the_title(); ?></h1>
<h2><?php echo get_post_meta(get_the_ID(), 'tipologia', TRUE);?></h2>
<p><?php the_excerpt(); ?></p>
<p class="read-more">
  <a href="<?php the_permalink(); ?>">Leggi tutto</a>
</p>
</div>
</div>


<?php
echo $args['after_widget'];

}
}
?>
<!-- #content --></div>

This is the code I use to extract the type of article created as a custom field which will then be used to filter the results:

<h2><?php echo get_post_meta(get_the_ID(), 'tipologia', TRUE);?></h2>
发布评论

评论列表(0)

  1. 暂无评论