Do not show children of a category

Just use the parameter category__in of WP_Query – if you do this, then there is no need for cat and category__not_in. category__in does give you back results from the categor(y/ies) specified, but does not include results for the children of the specified categor(y/ies).

Custom WordPress Table wpdb

First off, you should not be handing an untrusted input (in this case, $_GET[‘id’] to your database. Always SQL-escape the query and validate/sanitize the data. (In the code snippet below, it’s SQL-escaped using $wpdb->prepare() for escaping and int typecasting to sanitize to integer value). Secondly, the $wpdb object provides more than just the query() function. … Read more

get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)

The ‘posts_per_page’ => -1, and ‘nopaging’ => true, shouldn’t be in your tax_query params. That might be what’s throwing it off. Try: $args = array( ‘post_type’=>’gpp_prod’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1, ‘nopaging’ => true, ); and: $args[‘tax_query’] = array( array( ‘taxonomy’ => ‘cat_prod’, ‘field’ => ‘term_id’, ‘terms’ => $category ) );

$wpdb->query can’t insert data

The following code will properly store data in wp_fafa: $wpdb->insert( $wpdb->prefix . ‘fafa’, array( ‘title’ => trim($row->item(0)->nodeValue), ‘liveprice’ => trim($row->item(2)->nodeValue), ‘changing’ => trim($row->item(4)->nodeValue), ‘lowest’ => trim($row->item(6)->nodeValue), ‘topest’ => trim($row->item(8)->nodeValue), ‘time’ => trim($row->item(10)->nodeValue) ), array( ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’ ) );

Create a post builder skin in a plugin

You cannot insert the do_action() inside the class like that, it’s gonna give you a fatal error. Instead you could use an array $skins to store all the skin functions (as closures), and the magic method _call() to call them: class skinclass { private $skins = array(); function __construct() { $this->skins = apply_filters( ‘add_skin’, $this->skins … Read more

How to reset usual $query on search page to push custom $wpdb query there?

This is not how pre_get_posts works. The pre_get_posts action gives developers access to the $query object by reference (any changes you make to $query are made directly to the original object – no return value is necessary). https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts What you are doing is simply wrong. You don’t “return” another query via pre_get_posts, you alter the … Read more

meta_value timestamp older than now

<?php $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘event’, ‘meta_query’ => array( array( ‘key’ => ‘event_date_end_timestamp’, ‘value’ => time(), ‘type’ => ‘numeric’, ‘compare’ => ‘<‘ ) ) ); $programs = new WP_Query($args); ?> <?php while($programs->have_posts()): $programs->the_post(); ?> <h1><?php the_title(); ?></h1> <?php endwhile; ?>