Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter larsstr

    (@larsstr)

    Wow, it works like a charm! Thank you very much for your long-term and intensive support, it is beautiful :)!

    Thread Starter larsstr

    (@larsstr)

    Now, I got the relevanssi_content_to_index hook working. My code is the following:

    function add_extra_content($content) {
        global $wpdb, $post;
        $content = $wpdb->get_col("SELECT meta_value FROM arowp_postmeta WHERE post_id = $post->ID AND meta_key LIKE 'beitragskapitel_%_headline' AND meta_key NOT LIKE 'beitragskapitel_%_erweiterung_headline'");
        return implode(" ", $content);
    }
    
    add_filter('relevanssi_content_to_index', 'add_extra_content');

    If I print $content all the headlines are imploded into a single string. But unfortunately, it seems that the weighing is unchanged. The order of my results are the same as before. I tried to add the add_filter([...]) command multiple times but that effects nothing. Do you have a solution for that? If it is easier with the premium version, it would not be a problem to buy that version :).

    Again, thank you very much for your stunning support!

    Thread Starter larsstr

    (@larsstr)

    I use the option custom fields to index in relevanssi settings (set to all). With that settings all my custom fields (including the repeater fields) are indexed.

    ACF Repeater stores the data in wp_postmeta table. In my case the repeater field is called “beitragskapitel”. The meta key for the first headline is beitragskapitel_0_headline. The second one is beitragskapitel_1_headline and so on. If there are 30 headlines on a page, the number increments to 29. If I use your hook, then I have to manually declare every headline in every post, haven’t I?

    BTW: There is a translation error in the german version. The description for the option custom fields to index presents the german words for “all” and “visible” but the textfield only accepts the original english words.

    Thread Starter larsstr

    (@larsstr)

    Mikko, thank you very much for your fast answer. I read the explanation of relevanssi_content_to_index hook (indexing-additional-content) but I’m not sure that this fits the requirements. There are a lot of posts on my site which consists of many data sets, constructed through the repeater field of ACF. So there can be multiple headlines on a side, which are generated with every data set from the repeater field.
    When I understand that hook, I have to manually declare every headline for every post (because of two parameters). Is there no dynamic solution?
    If the premium version is relevant, i would immediately buy it.

    Thread Starter larsstr

    (@larsstr)

    Oh, that was my fault. I misunderstood your Edit (I was so enthusiastic 🙂 ) and thought, that the second answer was the cleanest solution. However, it has surprised me that you called him Phil…. But now, it is clear and I changed my implementation to Phil’s solution :).

    Thread Starter larsstr

    (@larsstr)

    Wow! I’m impressed by your support speed and quality.
    I took your second advice, added a mysql-parameter to limit the output by a given maximum of values and now it works like a charm!

    For all interested people, here is my modified version (added output limitation by a given value as argument) of Héctor’s wonderful solution advice:

    if(!function_exists("get_popular_post_ids")) {
    	function get_popular_post_ids($args) {
    		global $wpdb;
    		$prefix = $wpdb->prefix . "popularposts";
    		$where = "";
    		$now = current_time('mysql');
    
    		/* Build the Query */
    		$fields = "p.ID AS 'id', p.post_title AS 'title', p.post_date AS 'date', p.post_author AS 'uid', v.pageviews AS 'pageviews'";
    
    		$from = "{$prefix}data v LEFT JOIN {$wpdb->posts} p ON v.postid = p.ID";
    
    		switch( $args['range'] ){
    			case "yesterday":
    				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
    				break;
    
    			case "daily":
    				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
    				break;
    
    			case "weekly":
    				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 WEEK) ";
    				break;
    
    			case "monthly":
    				$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 MONTH) ";
    				break;
    
    			default:
    				$where .= "";
    				break;
    		}
    
    		if(is_numeric($args['num'])) {
    			$num = " LIMIT ".$args['num'];
    		} else {
    			$num = "";
    		}
    
    		$where .= " AND p.post_type = 'post'";
    		$where .= " AND p.post_password = '' AND p.post_status = 'publish'";	
    
    		$orderby = "ORDER BY pageviews DESC";
    
    		$query = "SELECT {$fields} FROM {$from} {$where} {$orderby} {$num};";
    
    		$result = $wpdb->get_results($query);
    
    		$counter = 0;
    		$myIDs = array();
    
    		foreach ($result as $aPost) {
    			$theID = $aPost->id;
    
    			if ( !$theID == "" ) {
    				$myIDs[$counter] = $theID;
    				$counter++;
    			}
    		}
    
    		return($myIDs);
    	}
    }

    Thank you very much :)!

Viewing 6 replies - 1 through 6 (of 6 total)