• Resolved Diego Quintana

    (@diegoquintana)


    Hey everyone. I’ve been looking all over the place for this but just can’t get it to work.

    I need to get the get_calendar function to use both published AND future posts, and need to be able to choose which category of posts (or taxonomy) to use.

    I’ve tried pretty much every plugin there is out there but they all just have too many functions or just don’t work. I just need to hack get_calendar.

    I assumed this would be done by duplicating the get_calendar function and passing the post_status array and adding an extra field to the function, but I’ve seen it would involve using wpdb->posts and what not and from there on out I’m left hanging.

    Anyone knows how to do it or has seen a similar solution?

    Thank you so much in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    get_calendar() does have a filter that enables one to tweak the HTML output, but for your needs I don’t see this working well. I think you are right, you need to copy and rename the function, modifying as needed, and using the new function on your templates instead of get_calendar().

    Our concepts seem to diverge from there as I see no point in passing arrays or extra fields. The main problem is all of the function’s queries are hardcoded into the function and these are what need to be changed. Unless you require more flexibility than is apparent, simply hardcoding to meet your needs should work fine without passing more data.

    You are right though in that this will require extensive rewriting of all the $wpdb->get_*() calls. Adding the future status is simple enough. To those unaccustomed to SQL queries, joining in the tables required to limit queries by category is mind boggling. I know this very well. While I may be somewhat of an expert with PHP and WP, I’m equally clueless with SQL.

    I hate to admit this, it’s rather pathetic. What I do to come up with the required SQL query is to use WP_Query to construct the query, then hook ‘posts_request’ filter to see the actual resulting query string. Once I see how WP built the string, I can usually adapt it to meet my needs. By using such a cheat, you should be able to come up with the right query strings as well as I could.

    Beware, WP_Query generates some useless query clauses which you will not want, though it hurts nothing to include. One I always see is WHERE (1=1) AND. You need the WHERE of course, but certainly not (1=1) which will always be true. I’ve no idea how that gets in there.

    Thread Starter Diego Quintana

    (@diegoquintana)

    hey @bcworkz thanks a lot on your reply. It sure did point me in the right direction.

    In case it might work for someone else. I doubt it’s the cleverest of hacks, but it works for what I need at least.

    I ended up solving it by cloning the get_calendar function from wp-includes/general-template.php and pasting it as a new function in my functions.php

    Then I replaced the post_status from post_status = ‘publish’ to post_status IN (‘publish’,’future’) and added some code I found in another solution but worked.

    I’m deep in the code now so I apologize for keeping the explanation so vague. If anybody needs it, I’d be glad to write an in-depth solution.

    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_calendar future posts and choose category’ is closed to new replies.