Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Sebafaim

    (@sebafaim)

    Thanks !

    I made it works for product tags too, my code if anyone need it :

    add_filter('woof_text_search_query', function($where, $woof_text) {
     
        global $wpdb;
    
    	$product_ids = [];
    
    	//Search by ACF field
    	$product_acf = $wpdb->get_results("
    	SELECT posts.ID
    	FROM $wpdb->posts AS posts
    	LEFT JOIN $wpdb->postmeta AS postmeta ON ( posts.ID = postmeta.post_id )
    	WHERE posts.post_type IN ('product')
    	AND postmeta.meta_key = 'champs_de_recherche'
    	AND (postmeta.meta_value LIKE '%$woof_text%')", ARRAY_N);
    
    	if (!empty($product_acf)) {
    		foreach ($product_acf as $v) {
    	        $product_ids[] = $v[0];
    	    }
    	}
    
    	//Search by product tags name
    	$product_term = $wpdb->get_results("
    	SELECT posts.ID
        FROM $wpdb->posts AS posts, $wpdb->term_relationships as term_relationships, $wpdb->terms as terms
        WHERE posts.ID = term_relationships.object_id
        AND terms.term_id = term_relationships.term_taxonomy_id
        AND terms.name LIKE '%$woof_text%'", ARRAY_N);
    
    	if (!empty($product_term)) {
    		foreach ($product_term as $v) {
    	        $product_ids[] = $v[0];
    	    }
    	}
    
    	if (!empty($product_ids)) {
    		$product_ids_string = implode(',', $product_ids);
    		$where .= " OR $wpdb->posts.ID IN($product_ids_string)";
    	}
     
        return $where;
    }, 99, 2);
    Thread Starter Sebafaim

    (@sebafaim)

    This is the code I use :

    <?php
    $child_posts = types_child_posts(‘photo’);
    foreach ($child_posts as $child_post) {
    $imgTitle = $child_post->post_title;
    $imgUrl = $child_post->fields[‘photo-test’];
    $imgDesc = $child_post->fields[‘photo-desc’];

    $path_parts = pathinfo($child_post->fields[‘photo-test’]); //just for miniature
    $chemintest = $path_parts[‘dirname’]; //just for miniature
    $filenametest = “/”.$path_parts[‘filename’]; //just for miniature
    $miniaturetest = $chemintest.$filenametest.”-40×25.jpg”; //just for miniature
    echo ‘<;a href=”‘.$imgUrl.'” title=”‘.$imgDesc.'”><img src=”‘.$miniaturetest.'” alt=”‘.$imgTitle.'” height=”25″ width=”40″/>'</;a>;
    }
    /?>

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