Tag Info

New answers tagged

0

Data Insertion It's actually that easy, please follow the following procedures using wp_insert_post(): (Please note that, I assumed you've already registered a Custom Post Type called cars to store car information) <?php //checking whether the form is submitted and the nonce is verified if( isset( $_POST['x_submit'] ) && isset( ...


0

There is no post_name argument for WP_Query, if you're querying by slug, it's just name. Without that argument, your query just gets the latest post back.


7

First of all you really shouldn't be using query_posts(). Read this excellent explanation why. Then this is a perfect use case for transients. You just get the post once and then cache it for 24 hours using the Transients API. if ( false === ( $quotes = get_transient( 'random_quote' ) ) ) { // It wasn't there, so regenerate the data and save the ...


1

I wouldn't say it's not "normal", but it's above typical. The common minimum of queries would go like: main query (set of posts) functionality (menus, widgets, etc) data (terms and such) On a WP test data that would make something under 50 queries on home page. With object cache it will fall under 10 on repeat visits. Without knowing your set up — yes, ...


0

Maybe you can try with get_posts() and foreach loop for the second query instead of WP_Query and then you will have something like this: <?php $secondary_query = get_posts('category_name=students'); foreach($secondary_query as $secondary_post): echo "<li>" . get_the_title($secondary_post->ID) . "</li>"; endforeach; ?> With above ...


0

Use meta_query argument in the array. $custom_post_type = 'event'; $args = array( 'post_type' => $custom_post_type, 'post_status' => 'publish', 'meta_key' => 'event_date_and_time', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'posts_per_page' => -1 'meta_query' => array( array( 'key' ...


0

You can use meta_query, if you date information is saved in custom field. Like this: $args = array( 'post_type' => $custom_post_type, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'event_date_and_time', 'value' => current_time('Ymd'), 'compare' => '>=' ) ...


0

As David pointed out, wpdb::query() does not allow multiple calls. So yes, it is because of having the "SET @newnum = 0;" before your actual query. This kind of query is simply not possible as the backend prevents that in order to protect against SQL injection attacks. Besides of that, the technique I described in my blog serves a different use case which ...


0

you must implement logic for edge cases, you could get the posts and check when was the last time their rate meta was updated! depending on that you decide if you can display or not the post on your search result


1

Strictly regarding your question: get_object_taxonomies( 'user' ); since user is the $object_type that it is used when the author registers the taxonomy.


-1

What about this ? $query_withMeta_search = new WP_Query( array( "post_type" => "product", "s" => $search_query, "meta_query" => array( "key" => "_sku", "value" => $search_query, "compare" => "LIKE" ) ) );


0

I found solution. Grouping duplicated posts by ID. Just add this code to select query: GROUP BY wp_posts.ID Whole code (maybe it will help someone - not many examples of working pagination with select query around the internet :)): <?php global $wpdb; $date = date("Y-m-d"); $querystr = " SELECT * FROM wp_posts JOIN wp_ftcalendar_events ON ...


0

Working code: <?php global $wpdb; $date = date("Y-m-d"); $querystr = " SELECT * FROM wp_posts JOIN wp_ftcalendar_events ON wp_posts.ID = wp_ftcalendar_events.post_parent WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post' AND wp_ftcalendar_events.start_datetime >= '$date' ORDER BY wp_ftcalendar_events.start_datetime ASC "; ...


1

First of all you are trying to combine both of the tables by post_parent. $wpdb->posts.post_parent = $wpdb->ftcalendar_events.post_parent I guess data in the ftcalendar_events has children of posts table, try $wpdb->posts.ID = $wpdb->ftcalendar_events.post_parent Also you can try joining tables: SELECT * FROM $wpdb->posts JOIN ...


0

I solved it: Just in case anybody ever has any trouble querying a post with the same term of a Taxonomy in another Post Type. I'll post my answer below because I finally solved it on my own. <?php $terms = get_the_terms( $post->ID, 'supplier-tax'); foreach ( $terms as $term ) { $termID[] = $term->term_id; } $the_query = new WP_Query( array( ...


0

Make sure that the value portion of the data parameter's column=>value pairs must be scalar. If you pass an array (or object) as a value to be inserted you will generate a warning similar to mysql_real_escape_string() expects parameter 1 to be string, array given on line 880 in file /var/www/html/wp-includes/wp-db.php". Rather then above your code is ...



Top 50 recent answers are included