WordPress.org

Ready to get started?Download WordPress

Forums

WPeMatico
[resolved] Cannot get cron to automatically create posts (6 posts)

  1. pilot911
    Member
    Posted 1 year ago #

    WpeMatico version: 1.0

    I have set up WpeMatico per the instructions and set up about 30 campaigns.

    If i run a campaign from the all campaign's list or from inside a campaign itself everything works fine. However when i try to schedule using the internal cron or the host cron nothing happens.

    Just to be sure here is the set up:

    In the campaign i set following:

    Activate Scheduling to Yes
    Create a schedule every 20 mins, past the hour

    Check feed all ok and save the campaign.

    In the all campaigns screen the next run Next Run time is at 10.20 pm so that is fine in the future as expected.

    At 10.20pm the cron activates but nothing is posted. (there are posts in the feed).

    I notice that the data for Last Run and Next Run has not changed.

    I also tried setting a server level cron job (tick box in settings) to disable Wp-Cron.

    Use Cron job of Hoster and disable WP_Cron
    You must set up a cron job that calls:
    php -q /home/public_html/wp-cron.php

    This does not seem to work either.

    Any ideas.

    http://wordpress.org/extend/plugins/wpematico/

  2. Nate Reist
    Member
    Posted 1 year ago #

    Hey There,

    I am also running into this issue and think I may have uncovered the problem.

    In the functions.php file is the function

    function wpematico_cron() {
    		$args = array( 'post_type' => 'wpematico', 'orderby' => 'ID', 'order' => 'ASC' );
    		$campaigns = get_posts( $args );
    		foreach( $campaigns as $post ) {
    			$campaign = WPeMatico :: get_campaign( $post->ID );
    			$activated = $campaign['activated'];
    			$cronnextrun = $campaign['cronnextrun'];
    			if ( !$activated )
    				continue;
    			if ( $cronnextrun <= current_time('timestamp') ) {
    				WPeMatico :: wpematico_dojob( $post->ID );
    			}
    		}
    	}

    If you are at all familiar with the function with get_posts for wordpress you would instantly notice what might cause an issue. the parameter of the function numberposts is not set. By default wordpress get_posts will only get 5 posts. So in this case 5 campaigns will run. If you are fortunate to only have 5 campaigns that need to run you would be fine. If you have more though, like your 30, it will not get to all of them. The case I am working on has 570 campaigns in it.

    The Fix:
    add the argument 'numberposts' => -1 to that function. However be careful, editing a plugin file can have undesired results, and if you upgrade the plugin it will be overwritten.

    function wpematico_cron() {
    		$args = array( 'post_type' => 'wpematico', 'orderby' => 'ID', 'order' => 'ASC' , 'numberposts' => -1 );
    		$campaigns = get_posts( $args );
    		foreach( $campaigns as $post ) {
    			$campaign = WPeMatico :: get_campaign( $post->ID );
    			$activated = $campaign['activated'];
    			$cronnextrun = $campaign['cronnextrun'];
    			if ( !$activated )
    				continue;
    			if ( $cronnextrun <= current_time('timestamp') ) {
    				WPeMatico :: wpematico_dojob( $post->ID );
    			}
    		}
    	}

    A safer route maybe to create a simliar function and access the WPeMatico class to use it's functions, but for a quick fix that should do it.

  3. Nate Reist
    Member
    Posted 1 year ago #

    Sorry that functions.php file I refer to is located in wp-content/plugins/wpematico/app/

  4. pilot911
    Member
    Posted 1 year ago #

    Hi natereist,

    Thanks I am going to take a look tomorrow now.

    Appreciate the help.

  5. pilot911
    Member
    Posted 1 year ago #

    Hi natereist,

    It works perfectly. Thanks.

    I also posted a link back to this on the plugin designers website.

    Thanks

  6. etruel
    Member
    Plugin Author

    Posted 1 year ago #

    thanks to all. I'll include this at next release.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic