mariosem
Forum Replies Created
-
Hello,
As I wrote, the AI modified snippet is working properly.
Thanks
Yes, that’s correct.
Yes, I confirm what you wrote. But, talking about the subject of this thread, no debug log has been produced, and the snippet can neither be activated nor saved.
Hello, this is the error (site name edited):
[19-Nov-2025 06:46:55 UTC] PHP Fatal error: Cannot redeclare create_archived_post_status() (previously declared in /home2/XXXXXXX/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(663) : eval()’d code:2) in /home2/XXXXXX/public_html/wp-content/plugins/insert-headers-and-footers/includes/class-wpcode-snippet-execute.php(419) : eval()’d code on line 2
Actually, I think this is a different error, when today I activated your plugin and Code Snippets was also active. Currently, no other error is in the log. Moreover, no debug log is produced, after I changed the wp-config file, activating the debug.
Hello,
Yes, I can save and see any other snippets. The snippet show 4 related posts, using a weighting of 65% tags and 35% categories, from the last 12 months, with a small thumbnail (120px). It is made by AI, as you can imagine. It works perfectly in another site of mine. As an aside, I just asked the AI to rewrite the code, and the new one works also with your plugin.
This is the code of the one that cannot be saved:
/**
* Related Posts Box
* Mostra 4 post correlati basati su tag (65%) e categorie (35%)
*/
// Aggiungi il box dei related posts dopo il contenuto
add_filter('the_content', 'phastidio_add_related_posts');
function phastidio_add_related_posts($content) {
// Esegui solo sui post singoli, non su pagine o archivi
if (!is_single() || !is_main_query()) {
return $content;
}
global $post;
$related_posts = phastidio_get_related_posts($post->ID, 4);
if (empty($related_posts)) {
return $content;
}
$related_html = '<div class="phastidio-related-posts">';
$related_html .= '<h3 class="related-posts-title">Potrebbero interessarvi</h3>';
$related_html .= '<div class="related-posts-grid">';
foreach ($related_posts as $related_post) {
$thumbnail = get_the_post_thumbnail($related_post->ID, 'medium', array('class' => 'related-post-thumb'));
if (!$thumbnail) {
$thumbnail = '<div class="related-post-no-thumb"><span>📄</span></div>';
}
$related_html .= '<div class="related-post-item">';
$related_html .= '<a href="' . get_permalink($related_post->ID) . '" class="related-post-link">';
$related_html .= '<div class="related-post-image">' . $thumbnail . '</div>';
$related_html .= '<h4 class="related-post-title">' . esc_html($related_post->post_title) . '</h4>';
$related_html .= '<span class="related-post-date">' . get_the_date('j F Y', $related_post->ID) . '</span>';
$related_html .= '</a>';
$related_html .= '</div>';
}
$related_html .= '</div></div>';
return $content . $related_html;
}
function phastidio_get_related_posts($post_id, $limit = 4) {
// Ottieni tag e categorie del post corrente
$tags = wp_get_post_tags($post_id);
$categories = wp_get_post_categories($post_id);
if (empty($tags) && empty($categories)) {
return array();
}
$tag_ids = array();
$category_ids = array();
foreach ($tags as $tag) {
$tag_ids[] = $tag->term_id;
}
if (!empty($categories)) {
$category_ids = $categories;
}
// Query per post degli ultimi 12 mesi
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 50,
'post__not_in' => array($post_id),
'date_query' => array(
array(
'after' => '12 months ago'
)
),
'orderby' => 'date',
'order' => 'DESC'
);
// Aggiungi filtro per tag o categorie se presenti
if (!empty($tag_ids) || !empty($category_ids)) {
$tax_query = array('relation' => 'OR');
if (!empty($tag_ids)) {
$tax_query[] = array(
'taxonomy' => 'post_tag',
'field' => 'term_id',
'terms' => $tag_ids
);
}
if (!empty($category_ids)) {
$tax_query[] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $category_ids
);
}
$args['tax_query'] = $tax_query;
}
$related_query = new WP_Query($args);
$scored_posts = array();
if ($related_query->have_posts()) {
while ($related_query->have_posts()) {
$related_query->the_post();
$related_id = get_the_ID();
// Calcola il punteggio
$score = 0;
// Punteggio tag (65%)
if (!empty($tag_ids)) {
$post_tags = wp_get_post_tags($related_id);
$matching_tags = 0;
foreach ($post_tags as $post_tag) {
if (in_array($post_tag->term_id, $tag_ids)) {
$matching_tags++;
}
}
$tag_score = ($matching_tags / count($tag_ids)) * 0.65;
$score += $tag_score;
}
// Punteggio categorie (35%)
if (!empty($category_ids)) {
$post_categories = wp_get_post_categories($related_id);
$matching_cats = 0;
foreach ($post_categories as $post_cat) {
if (in_array($post_cat, $category_ids)) {
$matching_cats++;
}
}
$cat_score = ($matching_cats / count($category_ids)) * 0.35;
$score += $cat_score;
}
if ($score > 0) {
$scored_posts[] = array(
'post' => get_post($related_id),
'score' => $score
);
}
}
wp_reset_postdata();
}
// Ordina per punteggio decrescente
if (!empty($scored_posts)) {
usort($scored_posts, function($a, $b) {
return $b['score'] <=> $a['score'];
});
}
// Restituisci i top N post
$result = array();
$count = 0;
foreach ($scored_posts as $scored_post) {
if ($count >= $limit) break;
$result[] = $scored_post['post'];
$count++;
}
return $result;
}
// Aggiungi gli stili CSS
add_action('wp_head', 'phastidio_related_posts_styles');
function phastidio_related_posts_styles() {
if (!is_single()) return;
?>
<style>
.phastidio-related-posts {
margin: 40px 0;
padding: 25px;
background: #f8f9fa;
border-radius: 8px;
border-left: 4px solid #0073aa;
}
.related-posts-title {
margin: 0 0 20px 0;
font-size: 22px;
font-weight: 600;
color: #333;
}
.related-posts-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 15px;
}
.related-post-item {
background: #fff;
border-radius: 6px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.related-post-item:hover {
transform: translateY(-4px);
box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.related-post-link {
text-decoration: none;
color: inherit;
display: block;
}
.related-post-image {
position: relative;
width: 100%;
height: 120px;
overflow: hidden;
background: #e9ecef;
}
.related-post-image img {
width: 100%;
height: 100%;
object-fit: cover;
}
.related-post-no-thumb {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 48px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
}
.related-post-title {
margin: 0;
padding: 12px 12px 8px;
font-size: 16px;
font-weight: 600;
line-height: 1.4;
color: #333;
}
.related-post-date {
display: block;
padding: 0 12px 12px;
font-size: 12px;
color: #666;
}
@media (max-width: 768px) {
.related-posts-grid {
grid-template-columns: 1fr;
}
.related-post-image {
height: 150px;
}
}
</style>
<?php
}Forum: Plugins
In reply to: [Code Snippets] Too many minor updatesHello,
Thanks for your reply. In my site I’m using about a dozen plugins. No one has the release cycle of Code Snippets. And no one has the number of minor releases just to fix bugs of Code Snippets. In my opinion, that means that updates are not going smoothly. One plugin I’m using has a monthly release schedule and no subsequent fix updates.
Forum: Plugins
In reply to: [Super Page Cache] Percentage cached on CloudflareYes, it’s on.
Forum: Plugins
In reply to: [Super Page Cache] Percentage cached on CloudflareI’m using Litespeed Cache plugin, yes. I’ve disabled it to use your plugin.
Forum: Plugins
In reply to: [Super Page Cache] Percentage cached on CloudflareHi Kush,
Thanks for your reply.
I was asking because I’m getting on average 20%, and peaks never go above 40%.
Mario
Forum: Plugins
In reply to: [Super Page Cache] Use with wordpress.com and link to dashboardThanks @isaumya,
when I tried for the first time your plugin, the cache hit ratio plunged, and I had the problem of the disappearing link to the dashboard. That’s why I’ve given up. I will try again.
Moreover, in wordpress.com the .htaccess file is not writable.
Last question: do I have to use all the cache rules you show in your example, or just a few? I would like to keep things as simplest as possible.
Forum: Plugins
In reply to: [Super Page Cache] Use with wordpress.com and link to dashboardHi @isaumya,
thanks for your answer. I had already followed points 1 to 3, I had no page rules at all, I have meanwhile activated Smart Tiered Cache and Cache Reserve.
I will follow your suggestion about point 7.
Forum: Plugins
In reply to: [Cloudflare] Problem after update to WP 6.1I have deactivated and reactivated the Cloudflare plugin, now it works.
Hi Sybre,
thanks for your answer. Unfortunately, my site is quite old and has 8.000+ posts, and has rather heavy traffic. I think it’s better for me to wait for a transporter, in the future, before moving to TSF.
Thanks,
Mario
Currently I’ve added adsbygoogle.js