New answers tagged

0

$query = ("SELECT * FROM <tablename> WHERE user_id = {$user_ID}"); // string variable $stmt = $wpdb->prepare($query); Say your $user_ID is 9, this will get evaluated to: $query = ("SELECT * FROM <tablename> WHERE user_id = 9"); $stmt = $wpdb->prepare($query); and finally becomes $stmt = $wpdb->prepare("SELECT * ...


4

You should always use get_post_meta. Your attempt to micro-optimise using a raw SQL query will reduce not improve performance. When you fetch a post, WordPress bulk fetches its meta for performance reasons, so if you used get_post_meta it would already have the answer in memory. If your site has an object cache then it would remember it from previous ...


1

The param name is s not search. So your query ignores the search param and returns all cpts. And your $_GET input should be sanitized before use. 's' => sanitize_text_field( $_GET['q'] ),


0

This has been solved. add_action('admin_head', 'set_scheduled_today_tag', 99); function set_scheduled_today_tag() { global $post; $args = [ 'post_type' => 'wp_events', 'post_status' => 'any', 'numberposts' => -1 ]; $posts = get_posts($args); if ($posts) { foreach ($posts as $post) { ...


0

The wc_get_product_category_list() returns the list of categories as a string. To get the ID you need to retrieve the category as an object. Important thing to note: since the product can have multiple categories assigned to it, you have to account for it in your code. To retrieve product categories assigned to a product it's best to use the get_the_terms ...


1

Most likely your values $latitude and/or $longitude are not what you expect them to be. So radians($latitdue) becomes radians() or radians(''). For getting a single row, get_row() is usually the better choice instead of get_results(). $zipdetail = $wpdb->get_row( "SELECT * FROM `li_zipcode` WHERE `zip_code` = '$zipcode'", OBJECT ); If $zipcode ...


1

You're reassigning 1 to $i on every loop: if ( $i = 1) { This should be if ( $i == 1) { or even if ( $i === 1) { which will also compare the post type, which is best practice. In PHP, = is assignment, == is comparison:


0

You must change $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; To the following : $paged = (get_query_var('page')) ? get_query_var('page') : 1; There is a difference in page and paged for a static front page, You may find your Answer here : https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters Keep Posted


0

Managed to get what I wanted like so: // first query $first_ids = get_posts( array( 'post_type' => POST_TYPE_KIB_HIREK, 'posts_per_page' => 1, 'post_status' => 'publish', 'orderby' => 'date', // popular - ha a legolvasott 'tag_id' => 102, 'order' => 'DESC', 'fields' => 'ids',...


0

Okay finally got this working. For reasons I will not detail here, I preferred a pagination solution which uses ONE single callback which I use everywhere where I need the pagination. In other words, I call the callback call on both upon page load of the template pages needing the query AND as well when click on a pagination link OR applying any search ...


3

Because of this line: $paged = get_query_var( "paged" ) ? get_query_var( "paged" ) : 1; This is inside a function that is used on both an AJAX handler, and on a page request. get_query_var pulls the parameters from the main query ( aka the primary WP_Query that powers functions such as the_post, have_posts() etc ). But this will never ...


0

So I had this problem specifically when using ACF & when using a field that held a multiple select that had previously had been populated and now was empty. I had the issue that: 'relation' => 'AND', array( 'key' => 'field_name', 'compare' => 'EXISTS' ), array( 'key' => 'field_name', 'value' => ...


0

simple it's 'posts_per_page' not 'post_per_page' ^_^ wp_query reference (pagination-parameters)


0

Wanted to share my two cents. Indeed, the main $wp_query will only return the posts correlating to the current Pagination Parameters. Like Milo pointed out in the comments you can actually create a new query with a different set of pagination parameters (eg: nopaging, posts_per_page, posts_per_archive_page ...). We can mirror the main query parameters and ...


1

Couple of things to consider here: 1.) Try adding the meta query only if the value is present: $pairedThing = get_field('myThing'); $args = [ 'posts_per_page' => 2, 'post_type' => 'thing', ]; if ( ! empty( $pairedThing ) ) { $args['meta_key'] = 'identifier'; $args['meta_value'] = $pairedThing; } 2.) Account for posts without ...


Top 50 recent answers are included