Support

Account

Forum Replies Created

  • @apsolut

    We fixed the issue by placing the iframe link in another ACF. We did a lot of debugging with our hosting provider and it is because of the API requests you are doing to YoutTube.

    The way we loaded video’s on the front-end did to many requests getting the YouTube thumbnail. Everytime a visitor visits that page there was a request to youtube getting the thumbnail of the video, that is why we were blocked.

    Maybe this wil help you solving your problem? How do you load the video’s in the Front-end?

    Maybe you can post some code?

  • Fixed it with this function:

    function my_acf_prepare_field_wordpress( $field ) {
    	$current_user = wp_get_current_user();
    	if( $current_user->user_login != "User1" && $current_user->user_login != "User2") {
    		$choices = $field['choices'];
    		unset($field['choices']['your-field-option']);
    	}
    	return $field;
    }
    
    add_filter('acf/prepare_field/name=pakket-of-dienst', 'my_acf_prepare_field_wordpress');
  • I managed to get it to work this far:

    function my_acf_prepare_field_wordpress( $field ) {
    	$current_user = wp_get_current_user();
    	
    	if( $current_user->user_login == "Username" ) {
    		if( $field['value'] ) {
    			$field['disabled'] = true;
    		}
    	}
    	return $field;
    }
    
    add_filter('acf/prepare_field/name=pakket-of-dienst', 'my_acf_prepare_field_wordpress');

    The whole field is disabled with this function but I only need to disable a specific option of this select field.

    Is this possible, if yes, could anybody point me in the right direction?

  • Because when I use the rwp_after_saving_review nothing gets updated. The page doesnt refresh so for some reason no field updates are done on the childs of this provider the review is left behind…

    Template_redirect does work for some reason but that refreshes (updates) the fields of all childs and not just the fields of the childs where a user left a review.

    But never mind, I think it is to complicated for me to get this to work properly

    Thanks anyway

  • Hello John,

    That is exactly what it is.

    Where and how the “Average” rating is updated on the Provider post I dont know. This is a plug-in I’m using.

    I know the answer on the When, when a new review gets submitted on the Provider post.

    With this function:

    function when_a_review_gets_submitted ($review, $post_id) {
    // Do something
    }
    
    add_action('rwp_after_saving_review', 'when_a_review_gets_submitted', 11, 2);

    I can do something after a new review is submited.

    I want to do this:

    // Set up the objects needed
    $hosting_provider_query = new WP_Query();
    global $post;
    $hosting_pagina_titel = $post->post_title;  
    $search_all_pages = $hosting_provider_query->query(array(
        'post_type' => 'page',
        'post_status' => 'publish',
        //Only get pages where custom field 'name_hosting_provider' equals Page title
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'naam_hosting_provivder',
                'value' => $hosting_pagina_titel,
                'compare'   => '='
            ),
    
        ),
    ));
    
    // Loop through all pages and find Page's children
    $loop_through_all_child_pages = get_page_children( get_the_ID(), $search_all_pages );
    
    // Loop through everything we got back
    if(!empty($loop_through_all_child_pages)){
        foreach($loop_through_all_child_pages as $child_page){
            // get the ID of each childpage
            $get_child_page_ID = $child_page->ID;
            // get the ID of each parent page of the child pages
            $get_parent_page_ID = get_queried_object_id();
            // Get the average score from post_meta of the parent page
            $get_average_score = get_post_meta( $get_parent_page_ID, 'rwp_user_score', true );
            // update each custom field of the childs with the average score data from the post meta of parent page
            update_field('gemiddelde_score_hosting_provider', $get_average_score, $get_child_page_ID);
        }
    }

    I once got it working when adding the above script inside the function with this extra action:

    add_action( 'template_redirect', 'when_a_review_gets_submitted' );

    but this is causing an error now and nothing is getting updated.

    Error

    Warning: Missing argument 2 for when_a_review_gets_submitted(), called in /var/www/vhosts/domainname.nl/httpdocs/wp-includes/class-wp-hook.php on line 286 and defined in /var/www/vhosts/domainname.nl/httpdocs/wp-content/themes/hosting-vergelijker/functions.php on line 452

    You have any idea how to get this done?

  • Hello John,

    Thanks for your reply.

    Yes that custom field in all the child pages is the purpose of this whole thing.

    Every child page stands for a hosting package of a provider. Every provider has a average score that is pulled of the meta of the Provider page and put in the custom field of the child.

    Why? I’m using FacetWP for filtering through those packages and I need the average score of each hosting provider package to make the star rating filter to work.

  • I was already afraid of that, it all sounds rather complicated and maybe it is. But this is the way I set it up and basically it works now only I think the code (as you say) is not good.

    I have added some comment to the code, maybe it is more clear.

    I have also added an image that might be a better idea of how it is set up and what the intention is.

    The ultimate goal is to make a filter with the average score of each hosting package. So that someone can filter on the average score of each package.

    Code:

    function when_a_review_gets_submitted ($review, $post_id) {
    	
    // Set up the objects needed
    $hosting_provider_query = new WP_Query();
    global $post;
    $hosting_pagina_titel = $post->post_title;  
    $search_all_pages = $hosting_provider_query->query(array(
        'post_type' => 'page',
        'post_status' => 'publish',
    	//Only get pages where custom field 'name_hosting_provider' equals Page title
        'meta_query' => array(
    		'relation' => 'AND',
            array(
                'key' => 'naam_hosting_provivder',
                'value' => $hosting_pagina_titel,
    			'compare'	=> '='
            ),
    
        ),
    ));
    	
    // Loop through all pages and find Page's children
    $loop_through_all_child_pages = get_page_children( get_the_ID(), $search_all_pages );
    	
    // Loop through everything we got back
    if(!empty($loop_through_all_child_pages)){
        foreach($loop_through_all_child_pages as $child_page){
    		// get the ID of each childpage
    		$get_child_page_ID = $child_page->ID;
    		// get the ID of each parent page of the child pages
    		$get_parent_page_ID = get_queried_object_id();
    		// Get the average score from post_meta of the parent page
    		$get_average_score = get_post_meta( $get_parent_page_ID, 'rwp_user_score', true );
    		// update each custom field of the childs with the average score data from the post meta of parent page
    		update_field('gemiddelde_score_hosting_provider', $get_average_score, $get_child_page_ID);
    	}
    }
    	
    }
    add_action( 'template_redirect', 'when_a_review_gets_submitted' );
    add_action('rwp_after_saving_review', 'when_a_review_gets_submitted', 11, 2);

    Image:
    https://imgur.com/a/l7JfYSa

  • Hello John,

    Thanks for your answer but this is not what I meant.

    The meta value (rwp_user_score) of the parent page is updated when this function is being executed. When a user submits a new review this value is updated automaticly.

    Only the custom field (gemiddelde_score_hosting_provider) of all the child pages of the parent are getting the value from the parents meta value (rwp_user_score). This value gets stored in the custom field (gemiddelde_score_hosting_provider).

    The current function is doing this:

    – Get all pages where custom field value of naam_hosting_provivder equals the post_title
    – Then get all childs of this pages
    $alle_child_paginas_doorlopen = get_page_children( get_the_ID(), $doorzoek_alle_paginas );
    – in the for each loop store every child page ID in a variable
    $id_tonen = $pakket_hp->ID;
    – then get the Page ID of the parent
    $postid = get_queried_object_id();
    – then get the meta ‘rwp_user_score’ of parent page (ID)
    $some_value = get_post_meta( $postid, 'rwp_user_score', true );
    – and finaly update the field where it is al about
    update_field('gemiddelde_score_hosting_provider', $some_value, $id_tonen);

    My coding skills are not that great but I think this function is looping through every page and its childs. When the site goes online we expect to have over 100 parent pages and each parent has over 10 child pages.

    So I think it is a bit of an overkill to loop and update the field (gemiddelde_score_hosting_provider) of every child page if only one meta value of a parent gets updated.

    Better explanation

    While I am explaining this, I can clearly understand that it is not very clear what I am trying to achieve. Maybe it’s useful if I write it off completely.

    On a page, a user can leave a review. The average score is stored in the post_meta under ‘rwp_user_score’ of this page.

    Each page represents a hosting provider and each hosting provider has packages. Each package is a child of a hosting provider page and has a custom field called “gemiddelde_score_hosting_provider”.

    The average score stored in the post_meta of the hosting provider page I put in the custom field “gemiddelde_score_hosting_provider” for each package of this hosting provider.

    This is all done when a new review submitted.

    Only with the current function, all custom fields of the child pages of each parent page are updated again.

    This is a bit redundant as he only has to update the custom fields of the child pages of the parent page where a review is submitted at that moment.

    Is it possible to realize this with my current function?

  • Ok, I got it working but I think with this function he is checking every parent page with his childeren or not?

    Is there a way to only trigger everything for the parent and his childeren on the page where the review is submitted?

    This is the function I currently have:

    function rex_my_action ($review, $post_id) {
    	
    // Set up the objects needed
    $hosting_provider_query = new WP_Query();
    global $post;
    $hosting_pagina_titel = $post->post_title;  
    $doorzoek_alle_paginas = $hosting_provider_query->query(array(
        'post_type' => 'page',
        'post_status' => 'publish',
        'meta_query' => array(
    		'relation' => 'AND',
            array(
                'key' => 'naam_hosting_provivder',
                'value' => $hosting_pagina_titel,
    			'compare'	=> '='
            ),
    
        ),
    ));
    	
    // Filter through all pages and find Page's children
    $alle_child_paginas_doorlopen = get_page_children( get_the_ID(), $doorzoek_alle_paginas );
    	
    // echo what we get back from WP
    if(!empty($alle_child_paginas_doorlopen)){
        foreach($alle_child_paginas_doorlopen as $pakket_hp){
    		$id_tonen = $pakket_hp->ID;
    		$postid = get_queried_object_id();
    		$some_value = get_post_meta( $postid, 'rwp_user_score', true );
    		update_field('gemiddelde_score_hosting_provider', $some_value, $id_tonen);
    	}
    }
    	
    }
    add_action( 'template_redirect', 'rex_my_action' );
    add_action('rwp_after_saving_review', 'rex_my_action', 11, 2);
  • Hello John,

    Thanks for the reply.

    My programming skills are not very good so maybe you can help me on my way.

    What I want to realize is that he retrieves users data from the user who is logged in at that moment.

    So for example:

    I have a text field called “name_provider” with id “field_5b0bc22b22606”.

    This field is linked to a Custom Post Type. When a user posts a new message, the username of the logged-in user must automatically be entered in the “name_provider” field. So that when a user posts this new message his username is automaticly in the post.

    Could you help me get started with this?

Viewing 10 posts - 1 through 10 (of 10 total)