• Resolved nartoof

    (@nartoof)


    Hi,

    Before V5, I used a form to review at the category level.
    I created a custom field to let the user choose which product the review is assigned to.

    After submission, I used a hook to correctly assign the review to the product.

    It isn’t working anymore.

    Here is the end of my function to create the custom field :

    if( $query->have_posts() )
    		{
    			$config[$cat_slug] = [
    				'label' => $label,
    				'type' => 'select',
    				'required' => true,
    			];
    			
    			while( $query->have_posts() )
    			{
    				$query->the_post();		
    				$config[$cat_slug]['options'][get_the_id()] = get_the_title( get_the_id() );
    			}
    			wp_reset_postdata();
    		}	
    	}
    
        return $config;
    }
    add_filter('site-reviews/config/forms/review-form' , 'MSW_add_custom_field_to_site_review_partie_boutique');

    The problem is that the option values ??are no longer the post ID but a counter that increments.

    I can no longer find the post ID to assign it with the site-reviews/review/created hook

    After submission, I used this snippet on the hook to assign the review :

    if ( isset($_POST['site-reviews']['e-books'] ) )
    	{
    		$id_produit = intval( $_POST['site-reviews']['e-books'] );
    		update_post_meta( $id_review , '_assigned_to' , $id_produit );
    	}

    This will not work either because you have restructured the functioning of the plugin in database. Is there a new simple solution to assign a review to a post using PHP ?

    I now need to insert into the glsr_assigned_posts table and not update a post meta…

    I hope it’s clear
    Thanks for your help ??

    • This topic was modified 3 years, 9 months ago by nartoof.
    • This topic was modified 3 years, 9 months ago by nartoof.
    • This topic was modified 3 years, 9 months ago by nartoof.
    • This topic was modified 3 years, 9 months ago by nartoof.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Adding custom fields to Site Reviews is not supported here as stated in the pastebin link. However, here is a quick answer.

    1. You can simply do this:

    $posts = get_posts([
        'post_type' => 'product',
        'posts_per_page' => -1,
    ]);
    $config['assigned_posts']['options'] = wp_list_pluck($posts, 'post_title', 'ID');
    

    2. The second part is unnecessary. Simply use assigned_posts as the field name in your custom field and the review will be assigned to the selected product ID.

    Thread Starter nartoof

    (@nartoof)

    @geminilabs Thanks a lot for the advice ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom select field option value’ is closed to new replies.