Developer's Custom Fields
error using slt_cf_get_posts_by_custom_first (12 posts)

  1. Sean
    Posted 4 years ago #


    I'm trying to use the slt_cf_get_posts_by_custom_first function to display a list of posts belonging to a custom post type, ordered by the field type 'date'. I keep getting an error:

    Warning: usort() expects parameter 1 to be array, object given in /home/homebake/public_html/wp-content/plugins/developers-custom-fields/slt-cf-lib.php on line 289.

    Here is my code:


    Am I going wrong somewhere?



  2. Steve Taylor
    Plugin Author

    Posted 4 years ago #

    Hi Sean,

    First off, I wonder if this plugin might help managing events? http://wordpress.org/extend/plugins/simple-events/

    The more I look at slt_cf_get_posts_by_custom_first(), the more I'm wondering why it's in the code! I think what you've hit is an obvious bug - it should be sorting and returning $posts->posts, not just the $posts query object.

    But past that, doesn't the usort() with slt_cf_order_posts() just override the previous ordering by custom field?

    Let me know if you come up with anything, but for now I'm thinking this was code I imported from somewhere else, and stupidly didn't test properly, early on in the plugin's history before I released it. :-/

  3. Sean
    Posted 4 years ago #

    Thanks for getting back so fast - I'm giving Simple Events a try.

    I've installed and activated it, and already have a custom post type called 'event', but the date field is not showing up in the event screen.

    I do already have a bunch of other custom fields registered for events (including one called 'Date', which I've just removed) - could that be causing a problem?

  4. Steve Taylor
    Plugin Author

    Posted 4 years ago #

    Check inside Simple Events, you'll see how it defines a date field using the DCF plugin. The name of field is event_date, so don't use that in your own code.

  5. Sean
    Posted 4 years ago #

    Odd - it's just not working. No date picker in the admin screen, and no date column in the events list. Can't figure out why - none of the names clash.

  6. Steve Taylor
    Plugin Author

    Posted 4 years ago #

    Busy right now - all I can say is, re-read the Simple Events readme.txt, and try a little basic debugging output from slt-simple-events.php, see what's what.

    Sorry that's all I can offer now, keep me posted and I'll try to have a look when I get time.

  7. Steve Taylor
    Plugin Author

    Posted 4 years ago #

    Sean, sorry, I don't think I'll be fixing this for now:


  8. lowe_22
    Posted 4 years ago #

    Hi Sean and Steve,

    I was having the same issue with the plugin. I installed it, check for any namespace conflicts and after discovering no issues started debugging.

    I noticed both the plugin and your register_post_type functions are called on 'init' action.
    You need to make sure that WordPress calls your register_post_type function before the plugin 'init' action so that the post type exists before the plugin is activated.

    Do this simply by adding a priority of '1' to your register_post_type function, thus:

    function create_my_post_types() {
    	register_post_type( 'event',
    			'labels' => array(
    				... labels here ...
    			'public' => true,
    			'supports' => array( 'title', 'editor', 'thumbnail' ),
    			       ... more options ...
    add_action( 'init', 'create_my_post_types', 1, false );

    It works for moe now, so I hope that helps.
    Might be worth putting that as a note in your plugin readme, Steve? Or just add a lower priority to the plugin init action.


  9. Steve Taylor
    Plugin Author

    Posted 4 years ago #

    Olly, I'm not sure what you're talking about is relevant to this thread.

    But I see what you mean. The issue of registering custom post types happening after the plugin's init function has never come up, but I guess this may be pure chance!

    If I'm understanding the issue correctly, I think the best approach would be to change this line in the plugin:

    add_action( 'init', 'slt_cf_init' );


    add_action( 'init', 'slt_cf_init', 10000 );

    I would probably add a note in the docs too, but at least no one would have to alter their add_action, except in extreme circumstances.

    If you think I've understood your problem correctly, could you confirm, and maybe raise it as an issue on GitHub? Thanks!

  10. lowe_22
    Posted 4 years ago #


    Just to clarify, I'm referring to the Simple-Events plugin, not Developers Custom Fields plugin.

    Sean seemed to be having issues getting Simple Events to work and all his symptoms fitted mine exactly, and as I'd managed to sort those out with this fix I assumed it was relevant.

    Adding a priority of 10000 seems like a good idea. Will be happy to submit an issue on the Simple-Events GitHub for you


  11. Steve Taylor
    Plugin Author

    Posted 4 years ago #

    OK, I can see the confusion now! Note the title of this thread - it's about DCF. I suggested he use Simple Events, which Sean had a problem with - I assume it's the same problem as yours. But the thread is really about the slt_cf_get_posts_by_custom_first function in DCF not working.

    Anyway, it might be worth addressing the init issue on both plugins - thanks for raising this. And glad there's no probs with DCF :)

  12. lowe_22
    Posted 4 years ago #

    Ah, my bad. Sorry for the confusion - I stumbled on this post searching for issues with the Simple Events plugin didn't notice the title!

    Great plug-ins by the way, I think I'm using most of yours on my WP sites.

    Thanks, Olly

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Developer's Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic