WordPress ajax filter returning all posts when it should be filtering by category

Here is My code, it should be filtering by category, it displays all posts on any checkbox I click, I don’t know how to fix this, I have tried everything.

<form id="filter">     <?php         if( $  terms = get_terms( 'category', 'orderby=name' ) ) : // to make it simple I use default categories         foreach ( $  terms as $  term ) :             echo '<input type="checkbox" name="category[]" value="' . $  term->term_id . '" class="br">' . $  term->name;             echo '';         endforeach;         endif;     ?>     <div class="filter-output"></div> </form> 

Here is the js (coded inside a template page)

jQuery('#filter .br').click(function(){      // Declaratie van array     var choices = {};      jQuery('.contents').remove();     jQuery('.filter-output').empty();      jQuery('input[type=checkbox]:checked').each(function() {         if (!choices.hasOwnProperty(this.name))              choices[this.name] = [this.value];         else              choices[this.name].push(this.value);     });       console.log(choices);     jQuery.ajax({         url: '<?php echo admin_url('admin-ajax.php'); ?>',         type :'POST',         data : {             'action' : 'call_post', // Naam van de PHP functie             'choices' : choices,         },         success: function (result) {             jQuery('.filter-output').append(result);             // Voor testen - Resultaat (Kan later verwijderd worden)             //console.log(Resultaat);             //console.log(Keuzes);         },         error: function(err){             // Voor testen - Error (Kan later verwijderd worden)             console.log(err);             console.log(choices);         }     }); }) 


add_action('wp_ajax_call_post', 'call_post'); add_action('wp_ajax_nopriv_call_post', 'call_post');  function call_post(){  // Verkijgen van AJAX data: $  choices = $  _POST['choices'];   $  meta_query = array('relation' => 'OR'); foreach($  choices as $  Key=>$  Value){      if(count($  Value)){         foreach ($  Value as $  Inkey => $  Invalue) {             $  meta_query[] = array( 'key' => $  Key, 'value' => $  Invalue, 'compare' => '=' );         }     } } $  args = array(     'post_type' => 'post',     'meta_query' =>$  meta_query );  $  query = new WP_Query($  args);  //if( ! empty ($  params['template'])) {      ////$  template = $  params['template'];      if( $  query->have_posts() ) :          while( $  query->have_posts() ): $  query->the_post();              the_title();          endwhile;          wp_reset_query();      else :          wp_send_json($  query->posts);      endif;  //}  die(); } 

Anyone please help, I have been trying to make this work since yesterday and with no luck at all

Old News Blog Posts: To Delete or Not to Delete? (or Noindex?)

Hi guys,

I have ~ 1800 old news posts dating back to 2012.

These are car related and now outdated (2015 model update vs 2019 model update).

They get zero to little traffic, some are poorly written – But, they rank for keywords, add to my site structure and fill important categories
(i.e. porsche 911 > old and new news, product info, pricing, etc.).

Easy to say ‘just delete it’ but is there a better, appropriate way to handle this?

Google indexing all these outdated pages may be doing more damage than good, using up crawl budget and such.

I’m totally lost here – should I just delete/redirect those old pieces to more recent? Noindex them? Not worth updating them either.

Any suggestions? Appreciate your help as always!

Get array of posts from the current archive page loop

Classic WordPress loop (for example in archive.php) looks like this:

if ( have_posts() ) :     while ( have_posts() ) : the_post();         get_template_part( 'template-parts/content', get_post_format() );     endwhile; endif; 

I want to get an array of post objects on archive page without having to do this:

$  my_posts = array(); while ( have_posts() ) {   the_post();   $  my_posts[] = $  post; }  // $  my_posts is array of post objects 

Is there any simpler method to get it?

Query nested posts, return if top level post contains a child certain tags

I have posts sorted by two categories (chapter and paragraph). The paragraph post can contain several tags. Not custom post types.

The chapter has a relation (via ACF) to the paragraph.

I’m want to build a query where I can surface both chapters and paragraphs based on a single tag. For example:

Chapter: 1      Paragraph 1 - Tags (happy, joyful)     Paragraph 4 - Tags (sad)     Paragraph 8 - Tags (hungry)  Chapter: 2      Paragraph 2 - Tags (happy, joyful)     Paragraph 3 - Tags (sad)     Paragraph 5 - Tags (hungry)  Query - Tags = 'sad'      Returns Chapter 1, Chapter 2, Paragraph 4, Paragraph 5 

I have tested a very inefficient solution where I loop through each post, loop through each relation checking for the right tag. Then storing that post aside including the parent, making sure to not store duplicates. It returns things correctly, but adhorently slow.

I believe that the right path is to start with the tagged posts and then go upstream. The standard wp query parameters don’t seem to provide a clear way to accomplish this. Maybe a straight sql query instead?

WordPress custom taxonomy, posts urls

I have a custom taxanomy and posts. On my site there are categories and subcategories.

Now URLSs look like this:

post: domen/product/lorem-post/
category: domen/category/lorem-category/
sybcategory: domen/category/lorem-subcategory/

It is necessary to change this structure:

post: domen/lorem-category/lorem-post/
category: domen/lorem-category/
sybcategory: domen/lorem-category/lorem-subcategory/

Write SEO Articles, Blog Posts And Website Content for $5

Are you looking for… High qualitySEO friendlywell researched and unique… Article, Content, and blog writer? Do not panic you’re in for a treat. I’m a WRITING SPECIALIST who is WILLING to satisfy you. As a CREATIVE WRITER who knows the nitty-gritty in ARTICLE WRITING, CONTENT and BLOG POST. I’m the exact writer you have been crying for. I know the right NAVIGATION to take, to get you TOPPING THE SEARCH ENGINE WEB. I pride myself as a great Writer that is second to none and I’m are always working hard to maintain the top spot. Smiles! Working with me means working with the best. As a vocational and technical writer, I love your business and understand your audience which positions me in a better state to drive more online lead for you. Hence, you can confidently bank on me for all your writing projects. Why Blessedwriter? Expertise in content for every niche500 words premium contentOffer speedy delivery100% attention to instructionsplagiarism free Reader-friendly content.

by: blessedwriter
Created: —
Category: Article Writing
Viewed: 232

Posts relacionados WordPress

Fala galera,

estou desenvolvendo um tema wordpress, e em uma página eu uso uma função para pegar os posts relacionados, ele pega todos os posts até o atual. Porém ele não precisaria pegar o atual, qual seria a forma de excluir o post atual e mostrar realmente só os relacionados?

OBS: estou usando um custom_post_type=cursos


function postagem_relacionada() {      $  post_id = get_the_ID();     $  cat_ids = array();     $  categories = get_the_category( $  post_id );      if(!empty($  categories) && is_wp_error($  categories)):         foreach ($  categories as $  category):             array_push($  cat_ids, $  category->term_id);         endforeach;     endif;      $  current_post_type = get_post_type($  post_id);     $  query_args = array(           'category__in'   => $  cat_ids,         'post_type'      => $  current_post_type,         'post_not_in'    => array($  post_id),         'posts_per_page'  => '10'       );      $  related_cats_post = new WP_Query( $  query_args );      if($  related_cats_post->have_posts()):          while($  related_cats_post->have_posts()): $  related_cats_post->the_post(); ?>            <div class="card text-gray height-100p shadow-v2">               <a href="<?php the_permalink(); ?>">                 <img class="card-img-top" src="<?php echo get_field('imagem_do_curso') ?>" alt="">               </a>               <div class="p-4">                 <a href="<?php the_permalink(); ?>" class="h6">                   <?php the_title(); ?>                 </a>                 <button class="btn btn-primary btn-sm btn-pill" style="color: #191B31!important">                   + <?php echo get_field('quantidade_de_alunos_formados') ?> Alunos formados                 </button>               </div>             </div>            <?php endwhile;          // Restore original Post Data         wp_reset_postdata();      endif;  } 

Why can’t I see facebook posts for one person?

I don’t friend people on facebook or really do much besides post in groups. When I go to an individual’s facebook page, I can usually see their latest post. For one individual that I know, I can only see posts up to 2015. They have posts into Jan 2019. I’m not facebook friends with this person. They said nothing is blocked or anything and we can’t figure out what is wrong. Their facebook friends can see the latest posts.

This would imply I need to friend them. But then why can I see the latest posts from other people’s facebook timelines who I’m not friends with?

Or, what can be both look into that might provide some hints as to the problem?

Create social media posts for $5

I will help you achieve a formidable social media presence and promote your brand by creating professionally crafted posts suitable for the growth of your business, and designed to help you gain more attention fast.  This gig is for 30 days where posting will be done on all your accounts such as Facebook, Twitter, Instagram, etc once a day or as per your requirement. I also accept custom orders.  My services include: 1. Page Optimization of your accounts. 2. Remove spamming and foul content posted by others. 3. Daily posting of relevant content (using top relevant hashtags) 4.  Increase followers organically 5. Increased engagement 6. Designing Photos Platforms:   Facebook   Instagram   Twitter   LinkedIn   Pinterest   Google+    Redit

by: mojibul44
Created: —
Category: Social Posts & Management
Viewed: 258