FacetWP Question

26 views
Skip to first unread message

Toby

unread,
Jan 20, 2023, 4:41:26 PM1/20/23
to Minneapolis St. Paul WordPress User Group
Hi there, friends.  I'm using FacetWP, and I need to change what's displayed in the FacetWP results based on whether or not someone is logged in.  For example:
  • if logged in, show foo1 and foo2
  • if not logged in, show only foo1
So far, the only way I've found to do this is to force a refresh of the page like this.  It works but it's not ideal (e.g. no ajax update of the results).

Any ideas on either a code solution or an alternate way of thinking about the problem?

Thanks,
Toby

Matt @ GEEK with a personality

unread,
Jan 20, 2023, 5:14:49 PM1/20/23
to mpls-stpau...@googlegroups.com
Hey Toby,

On the Listings tab in FacetWP you can click on one of your items in the Listing column, then click the Dev mode checkbox on the right side.  This allows you to write your own code and you can add some php to check if they are logged in or not before displaying results.  Does this help?

Best!
Matt
---

Matt Christenson
GEEK, with a personality

WordPress Website Design, Graphic Design, Maintenance, Training, Hosting, and SEO
GEEKwap.com
Schedule a Phone Call with the GEEK!
Connect with the GEEK!
Like and Follow the GEEK!


--
You received this message because you are subscribed to the Google Groups "Minneapolis St. Paul WordPress User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpls-stpaul-word...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mpls-stpaul-wordpress/92e1c6d9-12fd-41db-942e-46474700ce0cn%40googlegroups.com.

Toby C

unread,
Jan 20, 2023, 7:50:54 PM1/20/23
to Minneapolis St. Paul WordPress User Group
Matt, I'm using the Dev view in FacetWP, and the page loads fine on initial load.  The issue is that when I click on any of the facets, the results no longer seem to know I'm logged in. I'll upload a video and code example later tonight to show what I mean.

Toby

Matt @ GEEK with a personality

unread,
Jan 20, 2023, 8:06:35 PM1/20/23
to mpls-stpau...@googlegroups.com
Ah, gotcha.  I get it.  That is outside of my wheelhouse.  Hope you get it resolved!

mc

Toby

unread,
Jan 21, 2023, 9:54:37 AM1/21/23
to Minneapolis St. Paul WordPress User Group
Here's a gist of what the code in my FacetWP dev view looks like:

<?php
if ( have_posts() ) :
  while ( have_posts() ): the_post(); 
    global $current_user;
    get_currentuserinfo();
    if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; } else { echo 'Welcome, visitor!'; }
  endwhile; 
endif; 
?>

The FacetWP results load fine on page refresh, however, when I select a facet, no matter what, the results think I'm not logged in (unless I do a page refresh).

Any ideas on what I'm doing wrong or how I might fix this?

Thanks,
Toby

Toby

unread,
Jan 23, 2023, 3:30:04 PM1/23/23
to Minneapolis St. Paul WordPress User Group
Thanks, Matt & Barbara.  I finally figured out the FacetWP "am-i-logged-in?" issue!  Strangely, the solution involved editing the WP Rest API, which, aparently, FacetWP relies on.  Thankfully, the Internet saved me once again after 3 long days of troubleshooting.  The Internet: The cause of and solution to all of our problems.

Toby


Reply all
Reply to author
Forward
0 new messages