Forum Replies Created
-
AuthorPosts
-
zisis19
ParticipantYES!! Thank you. You saved my weekend :D.
January 20, 2022 at 10:51 am in reply to: Search for media and exclude search from media in custom post type #36330zisis19
ParticipantThanks Ernest. You are a hero!!
January 20, 2022 at 6:18 am in reply to: Search for media and exclude search from media in custom post type #36320zisis19
ParticipantGoodmorning Ernest. I am sorry. Yesterday I was so tired that I completely forgot what I wanted to achieve in the first place with this search field. Your original code is working perfectly. In the excluded array, when I put my custom post type it indeed excludes attachments from it. That was my goal. So thank you for your help.
If you could answer also the question, how I can limit this code only to this search instance and not let it affect future ones, that would be great. Thanks 🙂January 19, 2022 at 4:57 pm in reply to: Search for media and exclude search from media in custom post type #36319zisis19
Participantadd_filter('asp_results', 'asp_remove_attachments_where_post_type', 10, 1); function asp_remove_attachments_where_post_type( $results ) { $included = array( 'newsroom' ); foreach ( $results as $k => $r ) { if ( isset($r->post_type) && $r->post_type == 'attachment' ) { $parent_id = wp_get_post_parent_id($r->id); if ( $parent_id != 0 ) { if ( in_array(get_post_type($parent_id), $included) ) { return $results; } } } } unset($results); }This did the trick. Instead of exluding an array I included it… Don’t know why the other way round didn’t work… I am just happy that it works now. Thank you for the initial code 🙂 .
PS: In the Plugin settings I removed any restrictions I had tried out regarding CPTs or Custom Fields.
PS2: One last question. Is it possible to limit this code only for one specific search instance? I named this one Dokumentenfinder as it searches only for dokuments. But what if I need to create a new search bar that will search for pages, posts etc… ? I created a second search instance for this as a test and I see that the above code applies to this new search instance as well. When I remove it, the 2nd one works just as it should… So, how can we limit this code only to the “Dokumentenfinder” search instance? It would be a shame not to be able to create more search instances in the future if needed :/.
January 19, 2022 at 4:15 pm in reply to: Search for media and exclude search from media in custom post type #36318zisis19
ParticipantThe same :/ . Funny enough, when I exclude in the exclude array my custom post type, I don’t get results from them, but when I exclude ‘post’, ‘page’, the search function finds everything, even the ones of the custom post type
January 19, 2022 at 4:07 pm in reply to: Search for media and exclude search from media in custom post type #36315zisis19
ParticipantThanks Ernest. Regarding the 2nd issue, the code worked perfectly, many thanks.
Regarding the 1st issue I still get some problems. First I corrected the
function asp_custom_footer_script( $results ) {
part to
function asp_remove_attachments_where_post_type( $results ) {
as the filter was named like that :).
but again I get results from pages or normal posts… Ideally I need dokuments that I have uploaded through a file upload field I created through advanced custom fields pro for this specific custom post type (‘newsroom’) :/PS. Why “if ( isset($r->post_type) && $r->post_type == ‘attachment’ ) {” …? I have created this custom post type like this:
register_post_type( 'newsroom', array( 'label' => __( 'newsroom' ), 'labels' => array( 'name' => __( 'Newsroom' ), 'singular_name' => __( 'Newsroom' ), 'add_new' => 'Neuen Newsroom Beitrag einfügen', ), 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', ), 'hierarchical' => false, 'rewrite' => array('slug' => 'newsroom','with_front' => false), 'public' => true, 'show_ui' => true, 'menu_icon' => 'dashicons-media-spreadsheet', 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'capability_type' => 'post' ) );-
This reply was modified 4 years, 4 months ago by
zisis19.
zisis19
Participantyep you can close it. I found the datepicker manual as well and now that I know the correct selector, I can play with it. Thanks
zisis19
ParticipantUhlala, it worked :). Thank youuu.
zisis19
ParticipantSure
WEB url: https://www.kgrp.de/also an admin account. You can find the datepicker when you login through the form on the top right > Ihr Konto and then the “Rundschreiben” Tab.
User: kgrp-ajaxsearchpro Pass: Ojq5$nL2Vg@Pc2C*6L
zisis19
ParticipantHi Ernest,
thank you for your reply. I just used the code in my functions.php but it didn’t do the trick :/. I can see the code with the debugger in the footer, but the range is still the same..zisis19
ParticipantLeft a 5 star review today. Thanks for the support. Awesome Plugin!!
zisis19
ParticipantSuper, that did the magic!!! Thank you so much.!!!
zisis19
ParticipantHi Ernest, here is the answer I got from ultimate members support.
Re: New Support Request: programmatical way to check if the user has access
Hi,Thanks for getting in touch. You can use following function to check if current logged in user has access to certain page/post, change $post_id to actual ID and you can replace “get_current_user_id()” with any user ID to check this.
function has_access() { $access = true; $restriction = get_post_meta( $post_id, 'um_content_restriction', true ); //This array contains all content restriction settings if ( isset($restriction['_um_access_roles']) ) { //this gives the array of restricted roles $access = UM()->Access()->user_can( get_current_user_id(), $restriction['_um_access_roles'] ); } return $access; }Do you think you can work your magic with this information? I’d really appreciate it as this filtered search that displays results according to the user role is the heart of the website we are building…
zisis19
ParticipantGoodmorning Ernest,
I think i found in the heir documents the correct fuction. It is called user_can(). https://ultimatemember.com/php-docs/classes/um.core.Access.html#source-view
If you click on the </> Icon, a popup will appear with the code of a template called access.php. In line 179 you can see how they use this function. I think this is what we need?I tried changing your code into this
add_filter( ‘asp_results’, ‘asp_filter_posts_by_capability’, 10, 1 );
function asp_filter_posts_by_capability( $results ) {
foreach ($results as $k => &$r ) {
if ( !user_can(get_current_user_id(), $restriction[‘_um_access_roles’]) )
unset($results[$k]);
}
return $results;
}
But it just broke the seach results completely… No pages were found regardless their restriction status… When I removed the ! from !user_can(… , then the search results appeared again, of course unfiltered (restricted pages were still shown).zisis19
ParticipantYou cannot access this content.
-
This reply was modified 4 years, 4 months ago by
-
AuthorPosts