• Resolved adrianistrate

    (@adrianistrate)


    Hello guys!

    My problem: I use the shortcode do_shortcode(‘[oacsspl]’); in a function that queries my blog posts, filtering them by a specific category. This function is placed in functions.php and no matter what I do, I can’t get anything desplayed.

    What I’ve tried with no success:

    1. I’ve tried the shortcode presented abose
    2. I’ve tried the shortcode with a default value like do_shortcode(‘[oacsspl post_id=751]’);
    3. I’ve downloaded from here the latest version of the plugin but the option it seems that wasn’t officially released.
    4. I’ve read all forum threads and saw that others did faced this problem but the solution for them (having a toggle to Enable Post Likes in Loop) is not available in the current version of the plugin.

    Please tell me if is a solution for this issue. I love the simplicity and efficiency of this plugin and I would like to have the posibility to use it with WP_Query results.

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author oacstudio

    (@oacstudio)

    Hi @adrianistrate,

    Thanks for reaching out! Could you share your function here? We will try and make it run.
    There is no option planned for this yet.
    This will always need custom code currently.

    Kind regards,

    Thread Starter adrianistrate

    (@adrianistrate)

    Hello there!

    Sure, below is the function that I use, with a template to display the rezults

    function filter_projects() {
    $catSlug = $_POST['category'];
    
    $ajaxposts = new WP_Query([
    'post_type' => 'post',
    'posts_per_page' => -1,
    'category_name' => $catSlug,
    'orderby' => 'menu_order',
    'order' => 'desc',
    ]);
    
    $article_list = '';
    
    if($ajaxposts->have_posts()) {
    while($ajaxposts->have_posts()) : $ajaxposts->the_post();
    $article_list = get_template_part('templates/project-list-item');
    endwhile;
    
    } else {
    //$response = 'No posts found…';
    //echo $newsletter_top;
    exit;
    }
    
    echo $article_list;
    exit;
    }
    
    add_action('wp_ajax_filter_projects', 'filter_projects');
    add_action('wp_ajax_nopriv_filter_projects', 'filter_projects');

    And project-list-item looks like this

    <?php 
    	$image_arr = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium_large');
    	$image_url = $image_arr[0];
    
    	$categories_arr = get_the_category(get_the_ID());
    	$categorie = $categories_arr[0]->cat_name;
    ?>
    
    <li>
    	<div class="blog_home_item_container">
    		<span class="blog_home_post_category"><?= $categorie; ?></span>
    		<img src="<?= $image_url; ?>" alt="post_image" onclick="location.href='<?= get_permalink() ?>';"/>
    		<div class="blog_home_item_text">
    			<label class="blog_home_post_date">
    				<i aria-hidden="true" class="fas fa-calendar"></i>
    				<?= get_the_date(); ?>
    			</label>
    			<strong class="blog_home_post_title" onclick="location.href='<?= get_permalink() ?>';"><?= the_title(); ?></strong>
    			 <!--<span class="blog_home_post_exerpt"><?= get_the_excerpt(); ?></span>-->
    			<div class="blog_home_post_info">
    			   <div class="blog_home_post_stats">
    					<span class="blog_home_post_views"><i aria-hidden="true" class="far fa-eye"></i> <?= do_shortcode('[post-views]'); ?></span>
    					<span class="blog_home_post_comments"><i class="far fa-comment"></i><?= get_comments_number(get_the_ID()); ?></span>
    				</div>
    				<div>
    				   <span><?= do_shortcode('[oacsspl]'); ?></span>
    				</div>
    			</div>
    		</div>
    	</div>
    </li>

    I would like to mention that I use the same template in a very similar script that I wrote with Code Snippets and the shortcode works there. The problem seems to be when I filter posts with the function located in functions.php file.

    Gin

    (@rawdolphe)

    Hi, I have a ‘similar’ but much simpler problem with the 2024 Theme:

    In my case the shortcode icon is NOT displayed in the Query Loop / Archives, BUT it works fine in the Single Post—either via the shortcode or when added automatically before / after the Content.

    Please make it work, thank you ??

    Yours sincerely,
    Gin

    Thread Starter adrianistrate

    (@adrianistrate)

    Hi @gin

    I solved my problem (and pretty sure will work for yours too) by making a change in one of the php files from the plugin.

    My complete step by step solution:

    1. Download the plugin zip file
    2. Unzip de plugin
    3. Go to solid-post-likes\views and find SolidPostLikesPublic.php file
    4. Open the file with a text editor
    5. Go to oacs_spl_display_like_button function
    6. at the end of the function you will find an if statement that specify to show the button only on single posts.
    7. Comment that IF statement and instead of that simply return $output;
    8. Save the file
    9. Zip back the entire content
    10. Upload the new zip archive into your wordpress site

    As fas as I’m concerned, my problem was solved and from this point of view I will mark this thread as rezolved.

    Gin

    (@rawdolphe)

    Hi @adrianistrate,

    Thank you, very much appreciatted.

    Can you please tell me what to enter exactly in part 7 (what does the line of code look like)?

    7. Comment that IF statement and instead of that simply return $output;

    Thank you,
    Gin

    Gin

    (@rawdolphe)

    Something like that?

    /** General output */
    
            if ($oacs_spl_show_likes_setting) {
                // only show on single posts.
                  //if(is_singular()) {
                  return $output;
                  }
            } else {
            // and not on archive pages.
                return;
            }
        }
    Gin

    (@rawdolphe)

    Actually, the above returned a fatal error, so I tried the following and now I get a triplicate heart icon, AND it selects / deselects all the posts in the query loop.

     /** General output */
    
            if ($oacs_spl_show_likes_setting) {
                // only show on single posts.
                  //if(is_singular()) {
                  return $output;
                  }
            //} else {
            // and not on archive pages.
                //return;
            //}
        }

    No worries?@adrianistrate, thank you again for your time – I’ll wait for an update and will keep looking for a suitable plugin. It’s just a question of time because many years ago there were many options out there. I don’t know what happened…. ?? We need a simple bookmark / favorite plugin for Gutenberg!

    Yours sincerely,
    Gin

    Thread Starter adrianistrate

    (@adrianistrate)

    Hi @gin

    A triplicate heart icon, funny, this is something I haven’t thought about :))

    Actually on step 7 you need to comment the entire IF statement and instead of that if, above of it, return the output.

    Here is how it looks and works on my end

    $oacs_spl_show_likes_setting    = carbon_get_theme_option('oacs_spl_show_likes');
    
    return $output;
    /** General output */
    
    //if ($oacs_spl_show_likes_setting) {
    //    // only show on single posts.
    //      if(is_singular()) {
    //      return $output;
    //      }
    //} else {
    //// and not on archive pages.
    //    return;
    //}
    Gin

    (@rawdolphe)

    Thanks @adrianistrate,

    Well, it made no difference; same as before, if you click on a heart it selects all the hearts in the page, then I get a triplicate – which goes away when I refresh the page :), regardless, all hearts are selected in the Query Loop / Archive template.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Shortcode not displayed in WP_Query results’ is closed to new replies.