PHP for bps_directory

BP Profile Search › PHP for bps_directory

  • Author
    Post
  • #9381 Reply
    Marek
    Guest

    Can you please give me the php code to replace the bps_directory short code (e.g. [bps_directory field_35=”Male” field_56=”Married”] ). I know I can use <?php echo do_shortcode(‘[name_of_shortcode]’); ?> but it would be nice to have the actual php.

    Thanks

    #9382 Reply
    andrea
    Plugin Author

    Hello Marek,

    The shortcode [bps_directory] doesn’t work like a standard shortcode, the hidden filters are ignored if you call it with do_shortcode() or if you simply replace it with some PHP code.

    If you are interested in the details, you can find the code for the hidden filters in bps-search.php, function bps_set_request(), while the rest of the shortcode is processed in bps-directory.php, function bps_show_directory().

    #9383 Reply
    Marek
    Guest

    Hi Andrea,

    Thanks for the quick response. I’ll dig through the code and see if I can come up with a work around. However, I’m wondering if there’s some simple way to include an “if” statement. I’m using a code that allows me to embed PHP in a WP page and have tried the following. It works except that WP parses the shortcode regardless of the surrounding PHP so the result always shows Men (the second shortcode instance) regardless of my if/else.

    <?php 
    
    global $wpdb;
    
    $user_sex = xprofile_get_field_data( 3, bp_loggedin_user_id() );
    
    if ( $user_sex == "Man" ) { 
      echo do_shortcode('[bps_directory field_3="Woman"]');
      }
    else {
      echo do_shortcode('[bps_directory field_3="Man"]');
    
      }
    
    ?>
    
    #9386 Reply
    andrea
    Plugin Author

    Hi Marek,

    I guess your PHP code is correct, but the shortcode doesn’t work as expected if you put two of them in the same page, because the last one overrides the others.

    At the moment the hidden filters only work if you insert a single [bps_directory] shortcode in a WordPress page.

    #9389 Reply
    Marek
    Guest

    Hi Andrea,

    Thanks again for your help. I managed to get it working by creating two separate pages, one for men and the other for women and redirecting the users accordingly. Not pretty but it works. However, I’ve noticed that now my pagination links don’t work for some inexplicable reason. Below is the actual code. You can see the URL and actual page are included in the original but not in those created using the short [bps_directory field_3=”Woman”] code.

    ORIGINAL LINKS

    <div class="pagination-links" id="member-dir-pag-bottom">
    			<a class="prev page-numbers" href="http://sd001.2ttx.com/members/?upage=1">?</a>
    <a class="page-numbers" href="http://sd001.2ttx.com/members/?upage=1">1</a>
    <span aria-current="page" class="page-numbers current">2</span>
    <a class="page-numbers" href="http://sd001.2ttx.com/members/?upage=3">3</a>
    <a class="page-numbers" href="http://sd001.2ttx.com/members/?upage=4">4</a>
    <a class="next page-numbers" href="http://sd001.2ttx.com/members/?upage=3">?</a>
    		</div>

    SHORT CODE GENERATED LINKS

    <div class="pagination-links" id="member-dir-pag-bottom">
    			<span aria-current="page" class="page-numbers current">1</span>
    <a class="page-numbers" href="?upage=2">2</a>
    <a class="next page-numbers" href="?upage=2">?</a>
    		</div>
    #9390 Reply
    andrea
    Plugin Author

    Hi Marek,

    What happens when you click on a pagination link?

    #9391 Reply
    Marek
    Guest

    Hi Andrea,

    Thanks once again for getting back to me. In creating two test pages to try and demonstrate for you what’s happening I figured out that my redirect code must have been interfering with the links. I’ll need to find another way to keep men of the woman’s page and women off the men’s page.

    Oddly however, I discovered that the test pageS I created with [bps_directory] and [bps_directory field_3=”Sugar Daddy”] work normally, but the page I created with [bps_directory field_3=”Sugar Babe”] now scrolls to the bottom of the page when you select page “2”, if you then click on page “1” it goes to the middle of the page. This doesn’t happen on the other two test pages so must somehow be related to the filter. Is there some way I can add something like

    $('html, body').animate({ scrollTop: 0 }, 'slow');

    to all pages?

    TEST 3 [bps_directory field_3=”Sugar Babe”] – WIERD pagination
    http://sd001.2ttx.com/test-3/

    TEST [bps_directory] – normal pagination
    http://sd001.2ttx.com/test/

    TEST 2 [bps_directory field_3=”Sugar Daddy”] – normal pagination
    http://sd001.2ttx.com/test-2/

    #9392 Reply
    andrea
    Plugin Author

    Hi Marek,

    Actually all your test directories scroll to the footer when you click on the last pagination link. Probably the standard Members directory does the same, could you check that?

    #9393 Reply
    Marek
    Guest

    Hi Andrea,

    Thanks for all your time and patience on this issue. I finally found a working solution. Thank you for this amazing plugin. In the end I simply removed the conflicting code (once I found it) and added the following to after the shortcode call, which is what I wanted anyways 🙂

    
    <script>
    $(document).ajaxComplete(function () {
      $(window).scrollTop(0);
    });
    </script>
    

    Thanks Again

    Marek

    #9394 Reply
    andrea
    Plugin Author

    Hi Marek,

    You are welcome, I’m glad you found a suitable solution!

Reply to: PHP for bps_directory
My Information