Forum Replies Created

Viewing 15 replies - 1 through 15 (of 63 total)
  • sure, this is what I would try, then you look for POST ID and categories if they are empty.

    <!-- related posts start -->
    <?php
    
    
    // Get the categories for the current post
    $categories = get_the_category( get_the_ID() );
    
    echo "POST ID: ".get_the_ID();
    echo "<br> CATEGORIES: <pre>";
    print_r($categories);
    echo "</pre>";
    
    
    // Get an array of category IDs
    $category_ids = array();
    foreach ( $categories as $category ) {
        $category_ids[] = $category->term_id;
    }
    
    // Get the tags for the current post
    $tags = wp_get_post_tags( get_the_ID() );
    
    // Get an array of tag IDs
    $tag_ids = array();
    foreach ( $tags as $tag ) {
        $tag_ids[] = $tag->term_id;
    }
    
    // Query for related posts based on the categories and tags
    $related_posts = get_posts( array(
        'category__in' => $category_ids,
        'tag__in' => $tag_ids,
        'post__not_in' => array( get_the_ID() ), // exclude the current post from the related posts
        'posts_per_page' => 12 // Change this number to set the number of related posts to display
    ) );
    
    // If there are related posts, display them
    if ( $related_posts ) :
        ?>
        
    
        <div class="container"> <!-- container start -->
            <div class="row overflow-hidden publication-list"> <!-- row start -->
                <?php foreach ( $related_posts as $post ) : setup_postdata( $post ); ?>
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-4 col-xl-3">
                        <a href="<?php the_permalink(); ?>">
                            <div style="display:none">
                                echo "INSIDE POST: <br>";
                                echo "POST ID: ".get_the_ID();
                                echo "<br> CATEGORIES: <pre>";
                                print_r($categories);
                                echo "</pre>";
                            </div>
    
                            <div class="title-box mx-auto mb-0">
                                <h1 class="title-color"><?php the_title(); ?></h1>
                                <?php
                                if( has_post_thumbnail() ):
                                    the_post_thumbnail('homepage-thumbnail', array('class' => 'img-fluid'));
                                else:
                                    ?>        
                                    <img class="img-fluid" src="<?php echo get_template_directory_uri() . "/images/bg.jpg"; ?>">
                                <?php endif; ?>
                                <?php
                                $video_type = get_field('post_badge');
                                if($video_type!='select_type'):
                                ?>
                                    <div class="post-badge"><?php echo get_field('post_badge'); ?></div>
                                <?php endif; ?>
                            </div>
                        </a>
                    </div>
                <?php endforeach; ?>
                <?php wp_reset_postdata(); ?>
            </div>
            <div class="btn__wrapper custom_loadmore_btn_div">
                <a href="javascript:void(0);" class="btn btn__primary custom_loadmore_btn" id="load-more">Load more <i class="fa-solid fa-bolt-lightning"></i></a>
            </div>
        </div> <!-- container ends -->
       <script>
    let currentPage = 1;
    let loadedPosts = [<?php echo get_the_ID(); ?>]; 
    
    jQuery('#load-more').on('click', function() {
        currentPage++;
    
        jQuery.ajax({
            type: 'POST',
            url: '/wp-admin/admin-ajax.php',
            dataType: 'json',
            data: {
                action: 'weichie_load_more',
                paged: currentPage,
                post__not_in: loadedPosts 
            },
            success: function (res) {
                if(currentPage >= res.max) {
                    jQuery('#load-more').hide();
                }
                jQuery('.publication-list').append(res.html);
                loadedPosts = loadedPosts.concat(res.postIds); 
            }
        });
    });
    
        </script>
        <!-- related posts end -->
    			
    <?php endif; ?>

    Hello, have you tried doing and echo to the get_the_ID() and see that it is working? I read something about that does not work outside the loop, and if this does not work, you will not have a category list, nor be able to exclude the current post.

    Thread Starter Seba Ocano

    (@sebaocano)

    Thanks @gappiah I will try your suggestions and let you know.

    Forum: Fixing WordPress
    In reply to: Webpage Garbled

    I suggest you to check the PHP logs for errors, or enable WordPress debug mode to check what is causing the problem.

    Can you share a link to check the problem?

    Hi @hemasusi, I registered on the website using [email protected] then, changed to email+2@gmail, go to Gmail inbox, click accept change, and no logout.

    Then, (logged with [email protected]), edit email to [email protected], not visiting Gmail inbox and keep navigating the menus (account details, payment, preferences, etc…) and I was not logged out.

    I am not sure if I understand the problem correctly, but I am not able to replicate your error.

    P.S. I am using this generic emails accounts to explain, I can not share my real ones due to forum rules.

    Hi @hemasusi ,
    Question 1: yes, that line hide the errors from visitors.
    Question 2: I will suggest you to do all the debugging, fix the error, make all the changes to the custom plugin files, and after you finish everything, then you disable the debug mode, and delete this log file.

    The reason for doing this, is that the file route is the default one, and some malicious user could download this file and get information about the server. It’s not a huge security problem, but it’s a good practice to delete it after the end of debugging.

    That’s true, I usually enable errors, check the problem and go back to disable errors. Given that is not an option for you, I suggest you this:

    Edit wp-config.php file edit like this:

    define( 'WP_DEBUG', true );
    
    define( 'WP_DEBUG_LOG', true );
    
    define( 'WP_DEBUG_DISPLAY', false );
    
    @ini_set( 'display_errors', 0 );

    and check for logs in this file:
    wp-content/debug.log

    After checking this error, delete logs or move to other location for security, and also disable the debug mode.

    More detailed guide:
    https://blog.hubspot.com/website/how-to-set-up-wordpress-error-logs-in-wp-config

    I would have never imagined that the PHP version has relation with this CSS problem, thanks for letting us know.

    Forum: Fixing WordPress
    In reply to: Edit core classes
    Thread Starter Seba Ocano

    (@sebaocano)

    Thanks, @threadi, I will check what plugin is doing it or if it is the theme and let you know.

    Forum: Fixing WordPress
    In reply to: Edit core classes
    Thread Starter Seba Ocano

    (@sebaocano)

    Sure, this a post link: https://vivibosslink.com/dropshipping/

    It appears in all the posts.

    Forum: Fixing WordPress
    In reply to: Edit core classes
    Thread Starter Seba Ocano

    (@sebaocano)

    Hi @threadi. Thanks for your help, there is a website where this is shown in every post at the bottom with CSS that hides de code (display=’none’).

    Even if is not recommended, Is there a way to do it anyway? Maybe using a filter or hook? Seems that all your answers suggest that I should not do this or this is not necessary, but I would like to learn how to do modifications without changing core files, I think that it will be very useful in the future.

    After some more research, I think that I found the problem. You are using a reserved term, you can see the full list here where type appears:
    https://codex.www.ads-software.com/Reserved_Terms

    I am thinking that maybe you can set a redirection using .htaccess or maybe cPanel (or similar administration panel) to do a redirection.

    Let me know if you need help generating the redirections.

    You are welcome, let me know if you need more help implementing this.

    Forum: Fixing WordPress
    In reply to: Edit core classes
    Thread Starter Seba Ocano

    (@sebaocano)

    It’s a seo thing, I need to change because of suggestions of the Microsoft bing optimization tool.

    The html code is not even visible to visitors.

Viewing 15 replies - 1 through 15 (of 63 total)