Wordpress - SQL Query - wordpress

Im trying to write a query to get all posts that are in a certain category that have been posted in the last 60 days, but im unsure as to where to find category information on posts in the database.
There doesnt seem to be any info in the wp_posts table.
Could someone help me form this query, im quite confused.
Cheers,

The reason why the post table doesn't have categories is because all that is done through the taxonomy system (more info) (which takes a few minutes to get your head around).
You can just use query_post() function to query posts from a specific category (see category__in on the linked page). That takes the headache out of taxonomy query.
Alternatively, if you don't want to mess with the main loop (which query_post will), you can create an instance of WP_Query and loop through them with that.
Edit: This page might also interest you

Related

How do I get the trackback count of a post in wordpress without writing an SQL query?

How do I get the trackback count of a post in wordpress without writing an SQL query?
I tried searching Brave Search and I couldn't find anything helpful. To fetch the amount of comments a post has, get_comments_number() is the wordpress protocol function for it. But what if I want to fetch the amount of trackbacks a post has?
And also, do I have to be inside "the loop" to do this? What if I'm outside the loop?

How can I display Wordpress posts in a repeatable random order?

I would like to control the MySQL statement that Wordpress uses to give me a group of posts. Specifically, I would like to add this to the sql:
ORDER BY RAND(CURDATE())
This particular implementation has a fixed number of posts that will not be changing. However that would be boring for returning visitors and some posts that are down the page would likely never be seen. I would like to display the posts in a random order that is the same all day and then gets randomized differently the next day.
WP_Query allows for a rand function but it effectively does:
ORDER BY RAND()
The problem this causes me is that it randomizes differently each time it is queried. I want it to stay the same for every query all day. Seeding the randomizer with today's date accomplishes this. WP_Query however does not allow for seeding the randomizer. So how do I accomplish my desired end?

WordPress query multiple post_types/categories with weighted results

For a WordPress project I'm looking for a better solution to this problem:
The query should get a set of different post_types and taxonomies (like categories), based on the site visitors choice. For example, the user want to get results from normal posts, but also products (from WooCommerce) and other post_types like events and news (both separate post_types. The tricky part is, that the user wants to assign a weight factor to each. So if they select like posts = 1, products = 3, news = 4, they should get a number of posts, three times more products and 4 times more news.
Next step will be to include categories, also with the weight factor, which will make it even more complex, because for posts, I need to query another taxonomy than for products.
The only way I found to solve this, is to run a separate query for each post_type, like fetching 10 items from posts, 30 items from products and 40 from news, to match the weight factors, then combine the results. But this will not scale very well when I need pagination (for example, I want to show 50 entries on the first page, next 50 on second page).
I thought about collecting these single queries into a temporary table, but such a table will be available for the current session only, so it won't help with the pagination (as the temporary table would no longer exist, when the second page is shown).
Does anybody have an idea, how I could approach this task? I would like it according to the WordPress coding standards, so I would like to use WP_Query and the provided filters, because the site is also using geolocating and WPML for translation, so I really would like to avoid writing a low-level query where I have to include all these manually.
I'm not looking for a final solution, just want to collect some ideas.

Stripping out fields from Variation in Woocommerce

I'm going to go ahead with what i'm suggesting here, but i thought i'd try and get someones thoughts at the same time
Cutting off the fat
I've got several products with 700+ variations. This becomes an issue with wordpress saving that product because it panics when it tries to save 8000+ fields and causes intermittent saving and ends up losing data.
However, looking at the variations in the backend, there are several fields that i'm not using in each variation:
weight
dimensions
virtual
downloadable
stock qty
sale price (and schedule)
etc.
If i remove these, thats at least 6 x 700 field = 4200 less fields that wordpress has to deal with, which would make saving an actual possibility.
I'm going to just defy the gods for this one and edit the woo commerce template directly to test it out.
I'm not 100% sure how to create a function that would remove these fields without harming woocommerce at this moment in time, if anyone know how, that'd be fantastic
I'll let you know my results.
I just dug around in the class-wc-meta-box-product-data.php file and there does not seem to be any easy way to remove built-in input fields. You would probably have to re-write the entire metabox.
What might be possible is a JS solution whereby you remove the fields you don't want. I am not sure at all, but if WooCommerce has proper isset() checks on all the variables its save routine then it shouldn't crash.
Or you could remove Woo's save routine and replace it with your own?
Woo's save action:
add_action( 'woocommerce_process_product_meta', 'WC_Meta_Box_Product_Data::save', 10, 2 );
This, like re-writing the entire metabox, puts you at risk of things breaking whenever WC is updated.
Just out of curiosity, how does one get 700+ variations?

need help on wordpress feeds query parameters

may i know how do i set the number of feeds displayed on a word press blog?
for instance, i used
http://beautifulreminisciencezz.wordpress.com/?feed=atom&year=2009
But it returns me only ten results.
For blogger, I know the query parameter is 'max-results'
However,t here's nowhere in wordpress where they mentioned the query parameters for this.
Anyone have any idea?
I think you can set it from the Reading Settings in Wordpress.
I'm just starting with WordPress myself, but I did notice the paged=<num> query parameter to get that num'th page of results. Looks like combining this with order=ASC&orderby=date should allow full in-order import (over several pages) if you're doing this programmatically.

Resources