Tag Info

New answers tagged

1

The WordPress function get_posts() is making it's own instance of WP_Query that is not globally accessible: function get_posts($args = null) { // ... cut ... $get_posts = new WP_Query; return $get_posts->query($r); } so you could instead try $results = get_posts($args); echo count($results); to give you the array count of post objects ...


11

The API you offer in a plugin or a theme depends on the logic of that specific code. There is probably no guide that applies to all situations. I am a contributor for multiple plugins with APIs, and what I have learned so far is: Do not offer an API until you really know how people use your code. Release the first two or three versions without any API. ...


0

I have a few issues with the accepted answer - that doesn't make it wrong, but I'll post my own code below which I feel might have a better result for some people since I had the same question but wanted to do the same thing with less code. First, the above code creates "URL" type navigation items, which is fine for some people but I want to link to PAGES, ...


0

The template_redirect hook might be what you are looking for. function template_redir_wpse_97289($content) { // code or file include, for example } add_filter('template_redirect','template_redir_wpse_97289',1); That will fire just before the page template is loaded so you could use it to load your own templates.



Top 50 recent answers are included