echo var into wp_query

The “cat” variable need to be an ID of the category. It depends how you configured the ACF field in the backend. Maybe you should print_r($selected_cat) to see what’s inside the variable. it is probably an array with the full information of the category.

WP_Query() load selected post

You don’t need a query if you the know the post ID: <?php $post_id = absint( $_POST[‘post_id’] ); if ( ! $post = get_post( $post_id ) ) exit; // Error if ( $post->post_status !== ‘publish’ ) exit; // Might want to prevent script kiddies from accessing private content echo ‘<h4>’ . get_the_title( $post ) . … Read more

Conflict array_splice on loop and query in widget

Your code is quite messy which makes debugging hard, so I cleaned up your code a bit. The posts_results filter accepts two parameters, one being the posts results array, and the second one is the current WP_Query instance. So you can pass the second argument and then test for your conditions. I haven’t tested your … Read more

Different Loop for tag pages?

Your code is trying to use if statements to control which if statements are being used, etc, which is meta programming. It will not work, and it can never work. <?php if ( is_tag() ) { if ( have_posts() ) { while ( have_posts() ) { the_post(); } else { $paged = ( get_query_var(‘paged’) ) … Read more

How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?

Try adding return false; to prevent the default submit action of the click. $(‘.grp_getnew’).on(‘click’, function(){ var data = { action: ‘get_random_post_tu’, usecategory: $(‘#categoryselect’).val() }; $.post( ajax_object.ajax_url, data, function(response) { if ( response.status != ‘error’ ) { var $link = $(“<a href=”” + response.link + “”>” + response.title + “</a><span >” + response.content +”</span>”); $(‘.grp_content’).html($link); } … Read more

Group by custom field value (start and end times)

try this wich first stack all posts with same times $tabEvent = []; foreach ( $rand_posts as $post ) { setup_postdata( $post ); $start_time = get_field(“start_time”); $end_time = get_field(“end_time”); $index = “$start_time|$end_time”; // store all the posts with same times if (!isset($tabEvent[$index])) { $tabEvent[$index] = []; } $tabEvent[$index][] = $post; } foreach ($tabEvent as $index … Read more

Display specific page (that is child) content on parent page

You were being too specific/not passing the correct parameters into your wp_query. This should get you what you’re looking for: <?php $current_page_id = get_the_id(); $investor_content_query = new WP_Query( ‘post_parent’=> $current_page_id ) ); if ( $investor_content_query->have_posts() ) { while ( $investor_content_query->have_posts() ) { $investor_content_query->the_post(); the_content(); } } wp_reset_postdata(); ?>