This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • in reply to: Attachment as results stopped working. #37141
    zisis19zisis19
    Participant

    YES!! Thank you. You saved my weekend :D.

    zisis19zisis19
    Participant

    Thanks Ernest. You are a hero!!

    zisis19zisis19
    Participant

    Goodmorning 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 🙂

    zisis19zisis19
    Participant
    add_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 :/.

    zisis19zisis19
    Participant

    The 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

    zisis19zisis19
    Participant

    Thanks 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 zisis19zisis19.
    in reply to: datepicker year range for dropdown #34172
    zisis19zisis19
    Participant

    yep 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

    in reply to: datepicker year range for dropdown #34170
    zisis19zisis19
    Participant

    Uhlala, it worked :). Thank youuu.

    in reply to: datepicker year range for dropdown #34167
    zisis19zisis19
    Participant

    Sure
    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

    in reply to: datepicker year range for dropdown #34163
    zisis19zisis19
    Participant

    Hi 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..

    in reply to: Ultimate Member and Ajax Search Pro #28477
    zisis19zisis19
    Participant

    Left a 5 star review today. Thanks for the support. Awesome Plugin!!

    in reply to: Ultimate Member and Ajax Search Pro #28423
    zisis19zisis19
    Participant

    Super, that did the magic!!! Thank you so much.!!!

    in reply to: Ultimate Member and Ajax Search Pro #28417
    zisis19zisis19
    Participant

    Hi 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…

    in reply to: Ultimate Member and Ajax Search Pro #28331
    zisis19zisis19
    Participant

    Goodmorning 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).

    in reply to: Ultimate Member and Ajax Search Pro #28320
    zisis19zisis19
    Participant

    You cannot access this content.

Viewing 15 posts - 1 through 15 (of 17 total)