Querying a large number of posts including their custom fields data
There are a number of caching plugins that may work for you, or build the data on the admin side when posts are added/updated and save it in an option.
There are a number of caching plugins that may work for you, or build the data on the admin side when posts are added/updated and save it in an option.
post_parent should be the ID of the post parent, not the slug. Apart from that, your code should work. If not, look for any posts_* filters or pre_get_posts actions that might influence your custom query EDIT Something else I have missed, $args is already an array, so you do not need to add it another … Read more
Use get_terms with parent argument to get only direct children of a term. Use wp_list_pluck to extract an array of term IDs that can be passed to a query. $args = array( ‘parent’ => get_queried_object_id(), ); $terms = get_terms( ‘category’, $args ); $term_ids = wp_list_pluck( $terms, ‘term_id’ ); Also uses get_queried_object_id to get the ID … Read more
Your arguments should look like this : $args = array( ‘post_type’ => ‘product’, // No need for an array since you only query one post type ‘posts_per_page’ => 3, ‘tax_query’=>array( // The taxonomy query array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, // Can be omitted, default parameter, can also be ‘slug’ or ‘name’ (name should … Read more
I’m not sure what you’re doing with the above script, but here are some random suggestions: Avoid using the root user, for security reasons create another database user with less powers. Avoid using deprecated mysql_* calls. Use WP_Query() or get_posts() instead of hardcoded SQL queries. Use global $wpdb object if you really must use hardcoded … Read more
First you need to register your expected variables. Something similar to: function my_rewrite() { add_rewrite_tag(‘%ct_city%’, ‘([^&]+)’); add_rewrite_tag(‘%country%’, ‘([^&]+)’); } add_action(‘init’, ‘my_rewrite’, 10, 0); Then you need to create the rule which will redirect to your abm page. Note that you will need to discover your abm‘s ID, since you will need to pass it in … Read more
I found a solution. I have to use [‘post__in’] $resume_args = array(); $resume_args[‘post_type’] = ‘resume’; $resume_args[‘posts_per_page’] = -1; $resume_args[‘post__in’] = array(9046, 9346); //works! $resume_args[‘s’] = ‘gassi gehen’; $resumes = new WP_Query($resume_args);
At query level? Not possible. {db_prefix}_postmeta has only one field for value. WP serializes arrays before inserting them and deserializes after they’re out. So you have three choices here: If you really need this sorting at query level (pagination, maybe?) you have to rethink your information architecture and start using a separate custom_post_meta field for … Read more
In general, custom SQL queries are faster than the WordPress native funtions regardless. The real question is, are these custom SQL queries better, and the simple answer is “NO”. Lets look at a few important points to why not to use custom SQL queries: You loose all filters, in the case of WP_Query, you loose … Read more
You can most probably reuse the loop and run it twice. The first time to display the queried post and the second time to display the rest // Get the current post id being viewed $current_post_id = get_queried_object_id(); // Define your query and query arguments $args = [ // All your arguments ]; $q = … Read more