0

I'm building an options page which allows users to choose three posts and three custom images that display on the site's front page. I am using the Settings API to create a custom WP_Query which pulls all posts from 4 different CPTs ('resources', 'events', 'blog posts', and 'publications'), and populates the titles and IDs (hidden) of these posts into a dropdown so a user can select three accordingly.

Everything is working great except for one issue: it seems that the 'publications' post type does not display in the dropdown. Here is the snippet of my custom query setup, tied to the 'admin_init' hook:

add_action('admin_init', 'at_register_homepage_featured_settings');
function at_register_homepage_featured_settings() {

    /*
    * ...
    * register DB option and section which holds it
    * ... 
    */

    /* find all relevant posts to use for dropdown options */
    $args = array(
        'post_type' => array('at_publications', 'event', 'post', 'at_resources'),
        'posts_per_page' => -1,
        'orderby' => 'post_type title',
        'order' => 'ASC',
        'post_status' => 'publish'
        );
    $post_query = new WP_Query( $args );

    /*
    * ...
    * populate dropdown with $post_query results above
    * ... 
    */
}

The name of the post type is 'at_publications', and like I mentioned, all other CPTs are displaying correctly within the dropdown. In fact, this code works great on my local install, but just not on the production site.

I looked into what the max limit for a dropdown is, and most modern browsers seem to support thousands of items, so I don't think this is the issue (the 'publications' post type has 65 posts at the moment). Looking for any guidance or suggestions here. Thanks in advance!

  • I can remember a similar question on Stack Overflow. IIRC, the issue that that particular person had was something to do with some setting in some multilingual plugin. If you are using any such plugin, recheck your setting on that particular plugin page – Pieter Goosen Aug 2 '15 at 5:30
  • As a matter of fact, I am using WPML for multilanguage functionality. Do you by chance remember the specific SO topic or plugin setting that I would have to modify to get this to work? Thanks for your help! – Abel Thomas Aug 2 '15 at 14:56
  • Unfortunately not, but I'm dead sure the issue was actually WPML. The issue was something to do with the translation of the post type slug. This is unfortunately as far as I can help. Good luck with this :-) – Pieter Goosen Aug 2 '15 at 15:22
  • Yep, found the setting and answered my own question below. Couldn't have done it without your guidance, thanks mate! – Abel Thomas Aug 2 '15 at 15:40
2

All thanks to @PieterGoosen's comment, I figured out that this issue was due to a setting within the WPML (multilingual) plugin. Under the 'translation management'->'multilingual content setup' tab of the plugin settings, there is a section for 'custom posts'. In this section, my 'publications' post type was not set for translation, and this somehow prevented its posts from displaying within my custom query. Once this setting was changed, everything works as expected!

Hopefully this makes sense and will help someone else in the future. Cheers!

  • Thank you for posting a solution. Glad I could be of help :-). Enjoy – Pieter Goosen Aug 2 '15 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.