Tagged: 

Viewing 30 posts - 1 through 30 (of 31 total)
  • Author
    Posts
  • #1105947

    I updated my theme from version 2.4.2. The one who built the webpage had made some customization without making a child theme. After the update, some private posts was made public. These are custom post types made with the plugins CPT UI andACF . I looked in the old WordPress backup and found that before the update there was a header-q_a.php with the following code in the <head> to prevent posts of the type Q&A with the custom field status set to “private” from being displayed:

     if(get_field('status') != 'private'){
    
    	   if (function_exists('avia_set_follow')) { echo avia_set_follow(); }
        }
        else{
            echo '<meta name="robots" content="noindex,nofollow">';
        } 

    I tried to add if else statement to the header-q_a.php in my child theme around the existing line:
    if (function_exists('avia_set_follow')) { echo avia_set_follow(); }
    and have added get_header(‘q_a’); in single-q_a.php as it was before, but the posts still display. Is it possible for you to log in and have a look at it? I had to set my website in maintencance mode until this is fixed. I share my login details in the private content and a link to one of the private posts that have been made public.

    #1106580

    Hey guttogjente,

    Thanks for giving us admin and ftp access.
    Here are some of the things I’d like to point out:
    First, header-q_a.php will not be called, to make it work you need to rename it to header.php.
    Second, the code you posted will not make the pages set as private in the custom field to be private, it only adds this meta tag in header for example:

    <meta name="robots" content="index, follow" />

    Third, in the Document (sidebar), there’s a Visibility option and you can set it there to Private, so you won’t need the custom field anymore.
    Hope this helps.

    Best regards,
    Nikko

    #1107468
    This reply has been marked as private.
    #1108185

    Hi guttogjente,

    I see, will check out on that version and get back to you :)

    Best regards,
    Nikko

    #1108269

    Hi guttogjente,

    Please refer to private content.

    Regards,
    Nikko

    #1108556

    The problem now is that I have three versions of the content in if(!function_exists(‘avia_ajax_search’)) in functions-enfold.php, which makes it difficult to compare them and know what to keep and what to delete:
    1) The orginial from version 2.4.1
    2) The modified version 2.4.1 with custom code added by the person why made my webpage
    3) The newest version of functions-enfold.php from the current Enfold theme

    I see there have been some modifications in of the content in if(!function_exists(‘avia_ajax_search’)) from version 2.4.1 to the latest Enfold version. Do you think it might work to simply replace the content in if(!function_exists(‘avia_ajax_search’)) in functions-enfold.php in my child theme with the version that the person who made my webpage some years ago created? Or do I need to compare it with the changes in the newest version of Enfold as well?

    If I only want to modify the content in if(!function_exists(‘avia_ajax_search’)) in functions-enfold.php, do I only include that part in my child theme functions-enfold.php or should I include all the contact from the functions-enfold.php in my child theme as well? For functions.php I see that I only include my own functions in the child theme, so this file does not replace functions.php in the original theme files but just add on to it?

    • This reply was modified 5 years, 5 months ago by guttogjente.
    #1108744

    Hi guttogjente,

    If you’re using the latest version of Enfold, I would suggest #3 and then tweak it, with some modifications made by the dev in #2, it would be easier to track the modified code since you have the original version of the file in 2.4.1.

    As for modifying the content, just place the modified if(!function_exists(‘avia_ajax_search’)) in the functions.php of your child and it should work, and then for your own functions, just place it also in functions.php of your child theme. The child theme’s functions.php is designed that it won’t replace the functions.php of your parent theme but it just adds to it (you’ll notice this if you have a child theme with nothing in functions.php yet you can still use the functions in the parent’s functions.php).

    Best regards,
    Nikko

    #1108967
    This reply has been marked as private.
    #1109639

    Hi,

    Thank you for the update.

    We can’t help you trace back custom modifications that we didn’t made, unfortunately. You need to get in touch with the previous developers.

    What is the purpose of that modification? Maybe. we’ll be able to suggest a more simple solution.

    Best regards,
    Ismael

    #1109669

    Hello Ismael!
    I definitely agree that the best solution would have been to get i touch with the previous developer. As I mentioned earlier in this tread, I also tried to contact the company who made the webpage, but the company had changed and they could no longer help me. Our webpage is mostly run by me and another volunteers to answer questions from youths, which they ask anonymously. They do not leave any contact information in the Gravity Form, but get a 6-digit code in the confirmation message that is generated automatically (this coding I managed to add successfully). On submission, a draft of a custom post type with their question and the code is automatically generated. The custom post type is made with the plugins CPT UI and contains Advanced Custom Fields (ACF) .One ACF is “status” that can be set to either “public” or “private”. Later, they can check their answer by searching for that code. If the answer is not suitable for being public, because it contains private information that can be tracked back to the person, it is made private so only the person with the code can view it. Therefore, we can not use the built in “private” function in WordPress.”

    If you have other solutions to achieve the same functionality I appreciate your suggestions.

    Except for in one sentence, I did not modify the code, I just pasted the old modifications to the code in between the existing code where it had been before.

    One change that I suspect could make the code above break down is that Enfold 2.4.1 had:
    $defaults = array('numberposts' => 5, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false);
    which the former developer modified to:
    $defaults = array('numberposts' => 5, 'post_type' => array('post','Ordliste'), 'post_password' => '', );
    The latest Enfold had:
    $defaults = array('numberposts' => 5, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false, 'results_hide_fields' => '');
    So I tried to combine the latest version and the modification to:
    $defaults = array('numberposts' => 5, 'post_type' => array('post','Ordliste'), 'post_password' => '', 'suppress_filters' => false, 'results_hide_fields' => '');

    Also, I noticed that this is an “if”-sentence without any “else”-argument.

    #1110164

    Hi,

    Thanks for the update.

    We can’t access this post without logging in, which means it’s still private.

    // https://www.guttogjente.no/sporsmal-og-svar/kjaeresten-min-liker-a-bli-straffet-i-sengen/

    It doesn’t show in the AJAX search either. Please check the following screenshot.

    Screenshot: https://imgur.com/a/PUYHldD

    Could you give us an examples of the 6-digit codes and the post/posts they correspond to?

    Best regards,
    Ismael

    #1110176
    This reply has been marked as private.
    #1112367

    Hi,

    Have you enabled also a plugin like ” Search Everything ” which allows to search through custom fields?

    Best regards,
    Basilis

    #1112526

    I had deactivated ”Search Everything”, since the “Custom Search by BestWebSoft” plugin already allows search in Custom Fields. But enabled ”Search Everything” also now, in case it can help to solve this problem.

    #1112834

    Hi,

    The post with the code 359017 doesn’t display in the actual search results page. (see private field)

    Why did you set the post type value to “Ordliste”? The actual post type slug or name of the posts is “q_a”.

    
    $defaults = array('numberposts' => 5, 'post_type' => array('post','Ordliste'), 'post_password' => '', 'suppress_filters' => false, 'results_hide_fields' => '');
    
    

    You should change that to “q_a” or leave the post_type value to “any”.

    Best regards,
    Ismael

    #1112840

    Hello Ismael! I activated ” Search Everything ” after the comment from Basilis, but now I deactivated it again since I realized that the custom search does not work when it is activated. Now you can access https://www.guttogjente.no/?s=359017
    I updated my reply from June 13, 2019 at 4:53 am, where I meant to write that the former developer had changed the code to:
    $defaults = array('numberposts' => 5, 'post_type' => array('post','Ordliste'), 'post_password' => '', );
    I refer to that post again to see how I modified the code based on comparing with the latest Enfold code.
    ‘Ordliste’ is another custom post category, so it seems like it first handles the normal cases where no password is needed and all posts shall be displayed? It is only for q_a that some posts are private so code is needed. For all other post types (standard posts and ‘Ordliste’ they are always visible.

    #1113052

    Hi,

    Have you tried reverting the post_type back to “any” or change it to “q_a”? If “Ordliste” is a custom post category, then using it as a value in the post type parameter is invalid. You should remove it or replace it as suggested previously. If you want to fetch posts by category, use the “tax_query” parameter or the default “cat” or “category” arguments.

    // https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
    // https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    Best regards,
    Ismael

    #1113819

    Hello Ismael!
    I have added a PHP-file in the private content (zipped it to upload it in WordPress) which contains what I added to functions PHP with a clearer commenting of what the developer added, so it is easier for you to read the code. I meant to say that “Ordliste” is another custom post TYPE, (not category). I tried to change it to “any” and I also tried to replace that line with the default Enfold-code, but my site shows “Techical problem” if I try a search when the code from the attached PHP-file is added to my functions.php (you my try and log in and add the code to functions.php and see).

    Can it have to do with what Nikko pointed out in the first reply in this thread, where he wrote “header-q_a.php will not be called”?

    #1114839

    Hi,

    Thank you for the update.

    You can try the following snippet in the functions.php to replace the default get_posts function with a custom one whenever the search keyword is numeric and the character length is 6. The function will still use the get_posts function, but with a slightly adjusted query.

    add_filter('avf_ajax_search_function', 'avf_search_by_posts_code_callback', 10, 4);
    function avf_search_by_posts_code_callback($name, $search_query, $search_parameters, $defaults)
    { 
        if( strlen( $_REQUEST['s'] ) == 6 && is_numeric( $_REQUEST['s'] ) ){
          $name = 'avf_search_by_posts_code';
        }
    
        return $name;
    }
    
    function avf_search_by_posts_code( $search_query, $search_parameters, $defaults ) {      
        $search_meta = array(
            'meta_query' => array(
              'relation' => 'AND',
              array(
                  'key' => 'code',
                  'value' => $_REQUEST['s'],
                  'compare' => '='
              ),
      
              array(
                  'key' => 'status',
                  'value' => 'private',
                  'compare' => '='
              )
            )
        );
    
        $search_parameters['numberposts'] = 1;
        $search_parameters['post_type'] = 'q_a';
        $search_parameters = array_merge( $search_parameters, $search_meta );
    
        unset($search_parameters['s']); // remove search query
    
        $posts = get_posts( $search_parameters );
    
        return $posts;
    }

    Don’t forget to remove the “avia_ajax_search” modifications first.

    Best regards,
    Ismael

    #1114880
    This reply has been marked as private.
    #1115498

    Hi!

    Thanks for the update.

    You didn’t mention that “status” is a custom field, and not the default post status. Maybe I just missed it. Anyway, we adjusted the query a bit to query posts with that custom field.. The “test-2/” posts should appear in the AJAX search when you search for the code “359017”.

    Regards,
    Ismael

    #1115953

    Hello Ismael! Great that the post now is visible from the front page once the code is typed into the search field. I think we are almost done now.

    In the reply to you on June 13th I mentioned that we use Advanced Custom Fields (ACF) and that “One ACF is “status” that can be set to either “public” or “private”.” But that is a long time ago now, so I understood that you did not remember:)

    The only thing I am missing now is that the title and content from the Q&A posts with the ACF field status set to “private” should not be searchable. In the test post I made, the title is “Test title” and the content is “Test question from user”. If I search for “Test” or “question” on the front page (write it in the search field without clicking on the search icon or pressing enter), the post is still found (see screenshot). It should be hidden, so that it is only visible by searching for the code. However, it is hidden when I press the search button. https://www.guttogjente.no/?s=question and https://www.guttogjente.no/?s=test does not display this private post in the search results. In the plugin “Custom search” I tried to set “code” as the only searchable field for custom posts, but it did not help (it would also not be an ideal solution, since the public posts would not be searchable either then). Another thing that separate the private posts from the public ones is that they don’t have a featured image, if that could help to hide them in the search query.

    #1116846

    Hi,

    Thank you for the update.

    Is the “status” custom field present in every posts? If it is, then you can set the search to query only posts that are public when the search keyword used is not a 6-digit code.

    Include this code in the functions.php file along with the previous ones.

    add_filter('avf_ajax_search_query', 'avf_ajax_search_query_mod', 10, 1);
    function avf_ajax_search_query_mod( $search_query )
    {
    	$url = parse_url($search_query);	
    	parse_str($url['path'], $search_parameters);
    
    	$search_meta = array(
            'meta_query' => array(
              array(
                  'key' => 'status',
                  'value' => 'private',
                  'compare' => '!='
              )
            )
        );
    
    	$search_parameters = array_merge( $search_parameters, $search_meta );
    
    	return $search_parameters;
    }

    Best regards,
    Ismael

    #1116869

    The “status” and the three other custom fields are present only for the custom post type name/slug “q_a” (see screenshot of setting in the plugin Custom Fields). We also have a custom post type name/slug “ordliste”, but this should always be visible to all, so it does not contain any custom fields. Then we have the ordinary WordPress posts.

    #1117642

    Hi,

    Thank you for the update.

    That made it a bit complicated. Please remove the “avf_ajax_search_query_mod” function and the corresponding hook above and then replace the previous “avf_search_by_posts_code_callback” function with the following snippet.

    add_filter('avf_ajax_search_function', 'avf_search_by_posts_code_callback', 10, 4);
    function avf_search_by_posts_code_callback($name, $search_query, $search_parameters, $defaults)
    {   
        return 'avf_search_by_posts_code';
    }
    
    function avf_search_by_posts_code( $search_query, $search_parameters, $defaults ) {    
    	if( strlen( $_REQUEST['s'] ) == 6 && is_numeric( $_REQUEST['s'] ) ) {  
    		$search_meta = array(
    			'meta_query' => array(
    			'relation' => 'AND',
    			array(
    				'key' => 'code',
    				'value' => $_REQUEST['s'],
    				'compare' => '='
    			),
    
    			array(
    				'key' => 'status',
    				'value' => 'private',
    				'compare' => '='
    			)
    			)
    		);
    
    		$search_parameters['numberposts'] = 1;
    		$search_parameters['post_type'] = 'q_a';
    		$search_parameters = array_merge( $search_parameters, $search_meta );
    
    		unset($search_parameters['s']); // remove search query
    
    		$private = get_posts( $search_parameters );
    
    		return $private;
    	} else {
    		$posts = get_posts( $search_parameters );
    
    		$public = [];
    
    		foreach($posts as $post) {
    			//$status = get_post_meta($post->ID, 'status', true);
    			$status = get_field('status', $post->ID);
    			if( $status != 'private' ) {
    				$public[] = $post;
    			}
    		} 
    
    		return $public;
    	}
    }
    

    Best regards,
    Ismael

    #1117654

    Thank you so much, Ismael. You are really patient! I don’t know how I should have solved this without your help. I added the updated code according to your instructions, cleared cache and tested, but the problem I described in my reply on July 5 remains. I still get the search results for “Test” (see screenshot ) when I am searching in the test post title. The same happens when I am searching in the test post content (see screenshot) for my search for “question”.

    #1117759

    Hi,

    I forgot to update the $status variable name. I adjusted the functions.php file already, so you don’t have to edit it. The private “q_a” posts should not be searchable unless a code is used.

    Best regards,
    Ismael

    #1118663

    Thanks, now the posts are hidden within our website. Is there any way I can thank you? I was thinking about emailing Kriesi and thank for the good support, your help has been above my expectations:)

    When I discovered that the posts with the custom field “status” set to “private” had become visible, I changed the Visibility from “Public” to “Private” for all these posts, so that they are not visible for anyone. I tested the solution by changing the Visibility for one of the former q_a posts to “Public” again. The post is still found by Google and the content is catched, so it can be read through Google, even if I change the Visibility to “Code” and use the code again. Can we set that the q_a posts with the custom field “status” set to “private” shall be hidden (“nofollow” “noindex”) so we prevent them from being displayed by most search engines?

    If it is difficult to hide the previously published q_a posts with the custom field “status” set to “private”, we can delete them. But we need the new q_a posts with the custom field “status” set to “private” to be hidden. I also tried to create a new q_a post with the custom field “status” set to private. I also chose “Visibility: Password protected”. Then the post content can only be viewed by those who have the code. It is not found by Google, maybe because it takes some time for Google to discover it?

    #1118681

    Hi,

    You’re welcome! Always glad to be of help.

    Regarding the search index, this is probably why this snippet was added in your header.php file.

    
    if(get_field('status') != 'private'){
        if (function_exists('avia_set_follow')) { echo avia_set_follow(); }
    } else{
        echo '<meta name="robots" content="noindex,nofollow">';
    } 
    

    This sets the meta content to noindex and nofollow when the status is set to “private”.

    If you want Google to reindex the page, ask them to recrawl the site:

    // https://support.google.com/webmasters/answer/6065812?hl=en

    And yes, it may take some time.

    Best regards,
    Ismael

    #1118692

    Thanks for the quick reply! Nikko said in the first reply in this tread that “header-q_a.php will not be called”. It is in “header-q_a.php” that the code you mentioned in your last reply is included. The previous developer had also added a “taxonomy-q_a.php”, which is almost identical to the “taxonomy-portfolio_entries.php” which is included with the theme. I also have “taxonomy-q_a.php” in my child theme folder. In this file, header.php is called. In single-q_a.php, I have included get_header(‘q_a’); I just wanted to confirm that the code you mentioned in your last reply actually in run.

Viewing 30 posts - 1 through 30 (of 31 total)
  • You must be logged in to reply to this topic.