Set Transient on CPT

Submitting a full blown answer now that we’ve figured it out.


Transients can be hard to troubleshoot because if you save the wrong value to the database at first, you can be looking at an old—and bad—value, even if the code that sets your transient is now correct.

The two ways you can fix this are to temporarily use delete_transient() or use a plugin like Transients Manager. The plugin has the advantage of showing you the value of transients as well which can speed up troubleshooting.

In the example above, the simplest way is just to start the snippet like this:

<?php
delete_transient('graduate_student_query'); // this is the magic
if ( false === ( $graduate_student_query = get_transient( 'graduate_student_query' ) ) ) {
    // etc...

That means the old value gets cleared, the full code runs, the transient is resaved, and you get to see if you used the correct value now.

Then be sure to remove delete_transient() from the code. Otherwise, you’re deleting it and regenerating it every time and your code is even more inefficient than it was before!