سؤال

Scenario: I am creating collapsible panels in the sidebar and displaying ALL categories as DIVs and all Posts links in those category DIVs. Simple enough. I got all categories by get_categories('orderby=name&order=ASC') and now looping through every category to get ALL posts in each category.

Problem: The code get_posts('nopaging=1&category='.$category->cat_ID) gives me all posts but WITH content and other things too. All, I want is the permalink of the post. That's it. I believe using get_posts will thus create big overhead as there are around 1000 posts in over 20 categories.

Solution: A function or piece of code that can just get me all the posts in a category with permalink and without other stuff, especially content as it's the largest overhead.

هل كانت مفيدة؟

المحلول

Look into using a custom query to extract exactly what you want: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

You may want to also use wp_reset_query() after you've finished with your custom call because selecting a query can be a fun Gotcha in wordpress when things start overriding each other: http://codex.wordpress.org/Function_Reference/wp_reset_query

Edited after your comment: You'd need to be using a join between wp_term_relationships and wp_posts, possibly even a 3-way join with wp_term_taxonomy thrown in for good measure.

To be absolutely honest, I wouldn't even bother - it's a lot of work for not a lot of benefit. 1000 records isn't really that much, and Wordpress already uses indexes on wp_posts to optimise its' queries. You'd probably get much better results through using the wp super cache plugin to generate static HTML files for visitors ( http://wordpress.org/extend/plugins/wp-super-cache/ ) than by duplicating core WP queries with a handful of columns removed from the select.

نصائح أخرى

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top