Forum Replies Created

  • I’ve even hard coded the expiry date and it’s still not working… weird.

    $expiry_date = '2022-01-21';

  • None of these worked sadly.. I don’t understand the issue with my code. The posts aren’t changing to Expired when they should do.

    // Setup and Run Cron Job
    if (!wp_next_scheduled( 'hrl_expire_listings' )) {
    	wp_schedule_event( time(), 'daily', 'hrl_expire_listings' );
    add_action( 'hrl_expire_listings', 'listing_expiry_date' );
    // Setup Cron Job Function to expire posts and send out emails.
    function listing_expiry_date() {
    	global $post;
    	// Custom Post Type for listings, grab published posts
    	$args = array(
    		'post_type'      => array( 'post_type_listings' ),
    		'post_status'    => array( 'Publish' ),
    		'posts_per_page' => -1,
    	// The Query
    	$query = new WP_Query( $args );
    	// The Loop
    	if ( $query->have_posts() ) :
    		while ( $query->have_posts() ) :
    			// Get listing author details
    			$author_display_name = get_the_author_meta( 'display_name' );	
    			$author_email        = get_the_author_meta( 'user_email' );
    			// Get admin/site details
    			$admin_email     = get_option('admin_email');
    			$admin_sitename  = get_option('blogname');	
    			// Get the current date
    			$today = date('Y-m-d');	
    			// Get listing post published date (not pending date)
    			$published_date = get_the_date( 'Y-m-d' );	
    			$expiry_date = date('Y-m-d', strtotime($published_date.' +5 days'));
    			// If todays date is equal to or greater than the expiry date...
    			if ( $today >= $expiry_date ) :
    				// change post status to 'expired'
    				$postdata = array(
    					'ID'          => $post->ID,
    					'post_status' => 'expired',
    		endwhile; //endwhile The Loop
    	endif; //endif The Loop		
    } //end function listing_expiry_date()
  • Working code:

    		// WP_Query arguments
    		$args = array(
    			'post_type'      => array( 'post_type_listings' ),
    			'post_status'    => array( 'publish' ),	
    			'posts_per_page' => -1,
    			'meta_key' => 'listing_payment_options_listing_featured_listing',
    			'meta_value' => 1,	
  • I solved this by doing the following:

    Within the DB I located the user_meta table and changed meta-box-order_{$screen_id} from ‘side‘ to ‘normal‘.

    Hope that helps others.
    Thanks John for the advice.

  • Since my above issue, I have created another set of custom fields for the same admin edit screen (custom post type) and these fields appear below the main content as they should. Surely there is a way to move the others back?

    I shall check out the DB and see if I can edit it that way and post back asap.

  • I am using Gutenberg. I may have accidentally moved it to the sidebar but I’ve tried dragging it back over with no luck. It only drags above or below other sidebar sections.

    I’ve also tried re-saving it as ‘below content’ position but with no such luck.

  • This solved my issue:–cms-32303

    $productterms = get_the_terms( get_the_ID(), 'listing_location'  );
    	if( $productterms ) {	             
    	    $producttermnames[] = 0;	                     
    	    foreach( $productterms as $productterm ) {  	                 
    	        $producttermnames[] = $productterm->name;	             
    	$args = array (
    	    'post_type' => 'post_type_listings',
    	    'tax_query' => array(
    	            'taxonomy' => 'listing_location',
    	            'field'    => 'slug',
    	            'terms'    => $producttermnames,
    	$the_query = new WP_Query( $args );
    	if( $the_query->have_posts() ): ?>
    	    <section class="product-related-posts">
    	    <?php echo '<h2>' . __( 'Related Posts', 'tutsplus' ) . '</h2>'; ?>
    	        <ul class="product-posts">
    	        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    	            <?php endwhile; ?>
    	            <?php wp_reset_postdata(); ?>
    	<?php endif;
  • I have since found out that the $post_id is actually the page id where the acf form is located and not the actual post id for the post submitted…

    How do I grab the submitted post id or data?

    But still, I do not how to resolve this. Any help would be much appreciated.

  • Thanks for the help. But it’s still not redirecting with:
    add_filter('acf/save_post', 'stripe_payment_redirect', 20);

    I’ve tried removing the if statement and it still doesn’t redirect to payment.
    I need some sort of if statement though because I have the ability for users to edit the submitted post. And I do not want the redirect to fire when they are only editing.

    The strange thing is; when the if statement is removed; that when editing the submitted post, the redirect works?!

  • This snippet worked for me.

    add_filter( 'acf/get_valid_field', 'change_post_content_type');
    function change_post_content_type( $field ) { 
        if($field['type'] == 'wysiwyg') {
            $field['tabs'] = 'visual';
            $field['toolbar'] = 'basic';
            $field['media_upload'] = 0;
        return $field;
  • Actually, sorry but this isn’t working.

    It just redirects to the post submission page. When I remove the following:

    if (is_admin() || get_post_type($post_id) != 'post_type_listings') {

    and edit a post, it then redirects to the correct payment page. But still does not redirect to a payment page upon initial form submission.

    Strange?! Any ideas please!?

    Many thanks

  • Thank you for your help.

    I have one more issue though; it also fires when ‘editing’ a front end post. So I only want this to run when creating a new post. Is there a way to perhaps target that?


  • Ahh… I was looking at the wrong bit of code for my fix then!

    It was this snippet that stopped my code running, as you had mentioned:

    if($post_id != 'new') {
      return $post_id;

    I’m not sure though that this check is the right one though:

    if (is_admin() || get_post_type($post_id) != 'post_type_listings') {

    I have a custom user role on my website that can submit the form. So I’d only want them to be able to submit it and only once. (the form gets saved as pending state before I manually approve it).

    Any tips please?!

    Thank you for you help on this. Most appreciated.

  • No problem.

    ‘listing_payment_options’ is a group field.
    ‘listing_featured_listing’ is a sub field of that group and is a true/false field.
    ‘listing_package_options’ is also a sub field and is a button group field.

    I pasted the code (from the ‘if have_rows‘ ) into the single post template and it displays the correct field values so I know that is working fine.

    It’s just not redirecting after post submission. Here is my acf form code:

    				'id'           => 'Submit Listing Form',	
    				'post_id'      => 'new_post',
    				'field_groups' => array('group_610bc08a94306'),	
    				'post_title'   => true,
    				'post_content' => true,		
    				'form'	       => true,
    				//'return'       => $payment_url,
    				'new_post'     => array(
    					'post_type'   => 'post_type_listings',
    					'post_status' => 'pending',
    				'submit_value'    => __('Submit New Listing', 'hr-listings'),
  • Actually, the ‘listing_media’ is the group field. What resolved my issue was adding $post_id to the the end of ‘listing_media’.

    if (have_rows('listing_media', $post_id)) {
          while (have_rows('listing_media', $postId)) {

    Thank you

  • This sounds great. One question:

    Will this be able to sync the values entered into the fields? So if for example I update a custom field on Site B, then that value would be saved and synced to Site A too.


  • Solved!

    get_permalink() should be get_permalink($post_id)

  • So I can leave my code alone, but then add the code you’ve linked too (one of them, not both!), within my functions.php file – is that correct?

    Thanks for the reply, I really appreciate it.

  • Got it!

    the_field( 'youtube_share_url', 'widget_' . $args['widget_id']

  • I ended up re-writing most of the code and this is what worked in the end:

    // Create a cron job in order to check the custom field of 'job_listing_closing_date' against today's date. If the date has passed, set the job status to 'closed' and display different content on front-end.
    // Scheduled Action Hook
    function check_job_end_date( ) {
      global $post;
      $args = array( 
      	'post_type'       => 'job_listings',
      	'posts_per_page'  => -1,
      $listings = get_posts( $args );
    	foreach($listings as $post) : setup_postdata($post);
      $today = date( 'Ymd' );
      $expire = get_field( 'job_listing_closing_date', false, false );
    	$status = get_field( 'job_listing_job_status' );
    		if ( $expire < $today ) :
    			$status = 'Closed';
    			update_field( 'job_listing_job_status', $status );
    // Schedule Cron Job Event
    if ( ! wp_next_scheduled( 'job_listing_cron_job' ) ) {
    	wp_schedule_event( date( 'Ymd' ), 'daily', 'job_listing_cron_job' );
    add_action( 'job_listing_cron_job', 'check_job_end_date' );
Viewing 25 posts - 1 through 25 (of 77 total)