Tag Info

New answers tagged

0

The only way to do it is using a query filter I think function wpse156319_posts_where( $where, $query ) { global $wpdb; $where .= $wpdb->prepare( ' AND (' . $wpdb->posts . '.post_parent = %s OR ' . $wpdb->posts . '.post_author = %s)', $_POST['id'], get_current_user_id() ); return $where; } which you just add in the ...


2

You could also use the posts_orderby filter: function wpse155827_posts_orderby_price( $orderby ) { return str_replace( 'wp_postmeta.meta_value', 'substr(wp_postmeta.meta_value, 1)', $orderby ); } add_filter( 'posts_orderby', 'wpse155827_posts_orderby_price' ); $theQuery = new WP_Query( array( 'orderby' => 'meta_value_num', 'meta_key' => ...


0

You'll have to use the post_clauses filter to create some custom SQL: add_filter( 'posts_clauses', 'wpse155827_price_sort', 10, 2 ); function wpse155827_price_sort( $clauses, $wp_query ) { $orderby = $wp_query->get( 'orderby' ); $order = ( $wp_query->get( 'order' ) == 'desc') ? 'DESC' : 'ASC'; if( 'price' === $orderby ) { ...


0

You should not modify the wordpress DB via SQL unless it is a total emergency. Wordpress DB structure getting more complex with time and there are always possible intractions with plugins that you might bypass with direct SQL. What you should do is to write a small plugin that inserts the tags by calling using the relevant APIs.


0

As far as I remember the appropriate query for all public post types is post_type equals string any. You can use get_post_types() to retrieve a list, but be careful with arguments, since not post types are meant for public/front display.


1

add_action( 'pre_get_posts', 'add_my_post_types_to_query' ); function add_my_post_types_to_query( $query ) { if ( is_home() && $query->is_main_query() ) $query->set( 'post_type', 'any' ); return $query; } refer to http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters


0

Here's what I'd do. This is mildly tested. It gets the IDs of all the posts you need and then builds a single query to get the posts in the correct order. // get your page IDs, I assume this returns an array of integers $page_ids = get_pageslug(" 'first_page', 'second_page' "); // get your blog post ID $blog_ids = new WP_Query( array( 'post_type'=> ...


2

This is all depends on what queries do you run on a page, are you using simple or complicated queries etc. There are really no set minimum or maximum amount of queries to a page. You will need to look in context of your site specifically and weigh the amount of queries to what is actually happening on your page. Wordpress can be quite harsh on resources ...


0

Wordpress uses a lot of plugins and is very query heavy but the in spite of that, the front page uses 59 queries to generate itself. I think the default (on a vanilla WordPress install on the default theme) is 27 or something of that nature. The larger the number of queries, the slower the page is going to load and the more load you are going to put on your ...


2

For the sake of explanation, here is how to solve the problem. By default, wordpress doesn't include custom post types in the main query, that is why you only get posts from the post type post in the archive pages. Also, widgets by default also does not include custom post types. As @birgire described in the post I flagged as duplicate The Archive ...


0

Did a little bit of searching around this site and found some links that should help you achieve your goal 1) Search all posts that match a specific title - Found this nifty code on another thread here - A use case example of the above function here 2) Updating the "tags" for a specific post is fairly simple with this function: ...


0

You'll want to have a look at get_the_terms(). <?php // You need to define the post id from the post you are outputting in the right bar so that the left bar knows how to match up the terms $country = get_the_terms( $post->id, 'countries' ) $args = array( 'post_type' => 'side_menu', 'posts_per_page'=> 1, 'tax_query' ...


0

No, and in fact you should not include the wp-admin/includes/upgrade.php file in a plugin. There is no real valid use case for doing so. It doesn't do anything for you or add any useful functions for a plugin. As for your question, you say "it doesn't work" but you fail to define what that means. Providing the error messages you receive is useful when ...


3

Before we continue, I must point out this: $i=1; $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query -> query('post-format-audio'.'&paged='.$paged) This is exactly the same as: query_posts( 'post-format-audio'.'&paged='.$paged ); Which is terrible. When people ...


0

Try adding the following code to the top of your search.php template below the get_header() call: <?php global $query_string; $query_args = explode("&", $query_string); $search_query = array(); foreach($query_args as $key => $string) { $query_split = explode("=", $string); $search_query[$query_split[0]] = ...


0

Because I'm also storing the user IDs against each company, office and team post object as user taxonomy I can reverse the query and only include the user IDs assigned to that specific post object. A similar thing to what has been done here - http://mywebsiteadvisor.com/learning/tutorials/building-simple-groups-plugin-for-wordpress-tutorial/step-5/ Only ...


0

You make no attempt to check if the work has already been done. As a result on every page load the work will be done yet again and more posts created. Because of this, when WordPress attempts to run WP Cron, you'll get a second load, and a second run of the code. So do not run this on every page load via the init hook. The URL being fetched takes a long ...


1

The use of wpdb->insert and wp_insert_post both accomplish an SQL Insert, which is why you're seeing 2 records each time. You must use only one instance of an insert method, and then Pass $my_post to WP_Query CLARIFICATION As Milo points out in his comment wpdb->insert will insert into any table, while wp_insert_post is used to insert a post into ...


1

You can use posts_per_page to return all post from the database Just little modification in your WP query <?php $query = new WP_Query(array('post_type' => 'any','posts_per_page'=>-1)); ?> Try with this modification if it works for you.



Top 50 recent answers are included