Toolset

Custom logout

/** Custom Logout Shortcode
 */
 function custom_logout_link_func() {
            $return = wp_logout_url();?>
            <a href="<?php echo $return; ?>" class="btn btn-primary btn-xs btn-block" role="button" style="margin-bottom: 10px;">Logout</a>
            <?php
        }
         
    add_shortcode('logout_link', 'custom_logout_link_func');
/**
 *Used to redirect after logout 
 */
 
function logout_page() {
    $login_page  = home_url();
    wp_redirect( $login_page . "" );
    exit;
}
add_action('wp_logout','logout_page');

https://toolset.com/forums/topic/create-a-logout-link/

WP-Cred login form: redirects based on different member roles

/**
 * Redirect user after successful login.
 *
 * @param string $redirect_to URL to redirect to.
 * @param string $request URL the user is coming from.
 * @param object $user Logged user's data.
 * @return string
 */
function my_login_redirect( $redirect_to, $request, $user ) {
    //is there a user to check?
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check for admins
        if ( in_array( 'administrator', $user->roles ) ) {
            // redirect them to the default place
            return $redirect_to;
        } else {
            return home_url();
        }
    } else {
        return $redirect_to;
    }
}
 
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

function my_login_redirect( $redirect_to, $request, $user ) {
    if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied
        return $redirect_to;
    }
    //is there a user to check?
    if (isset($user->roles) && is_array($user->roles)) {
        //check for subscribers
        if (in_array('subscriber', $user->roles)) {
            // redirect them to another URL, in this case, the homepage
            $redirect_to =  '<em><u>hidden link</u></em>';
        }
 
        if (in_array('contributor', $user->roles)) {
            // redirect them to another URL, in this case, the search page
            $redirect_to = '<em><u>hidden link</u></em>';
        }
 
        // copy and paste the block above for each role
    }
 
    return $redirect_to;
}
 
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

https://toolset.com/forums/topic/need-to-have-1-login-form-that-redirects-based-on-wp_user-role/

Primera letra de cada custom post type

[wpv-layout-start]
    [wpv-items-found]
    <a href="[current_url]">All</a>
    <!-- wpv-loop-start -->
        <wpv-loop>
            <a href="?wpvalphabet=[wpv-taxonomy-title]">[wpv-taxonomy-title]</a>
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]
add_shortcode( 'current_url', function(){
    
    $request = $_SERVER['HTTP_HOST'].strtok($_SERVER["REQUEST_URI"],'?');
    $protocol = 'http://';
    
    if ( isset($_SERVER['HTTPS']) ) {
        $protocol = 'https://';
    }
    
    return $protocol . $request;
} );
wpv-layout-start]
[wpv-view name="alphabet-terms"]
[wpv-items-found]
<!-- wpv-loop-start -->
        <wpv-loop>
            <h3>[wpv-post-link]</h3>
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]
add_filter('wpv_filter_query', 'func_filter_by_title', 10, 2);
function func_filter_by_title($query, $setting) {
  
global $wpdb;
      
if($setting['view_id'] == 9999) {
          
        if(isset($_GET['wpvalphabet']) and $_GET['wpvalphabet']!='' ){
              
              
            $first_char = $_GET['wpvalphabet'];
            $postids = $wpdb->get_col($wpdb->prepare("SELECT      ID
                                                        FROM        $wpdb->posts
                                                        WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
                                                        AND post_type = '".$query['post_type'][0]."'
                                                        AND post_status = 'publish'
                                                        ORDER BY    $wpdb->posts.post_title",$first_char)); 
                                                          
                  $query['post__in'] = $postids;
                  }
  }
return 

https://toolset.com/forums/topic/show-hidden-links/#post-1612419

Cambiar entre lista y cuadrícula en una vista de Toolset

Queremos cambiar en una vista de Toolset entre una lista de registros y una cuadrícula de registros.

Primero crearemos 2 páginas, llamadas grid-view y list-view, y en cada una de ellas insertaremos los siguientes enlaces:

<a href="/grid-view/" class="switch">Grid</a> | <a href="/list-view/" class="switch">List</a>

Crearemos 2 vistas iguales e insertaremos el siguienre js en las mísmas:

jQuery( function( $ ) {
  $( 'a.switch' ).click( function() {
    var url = this.href + '?' + window.location.href.split('?')[1];
    window.location.href = url;
    return false;
  } );
} );

Visto en el foro de Toolset

Usar Toolset Views y modal de Bootstrap para mostrar contenido

// this part displays the trigger for the modal
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".xmit-modal-sm-[wpv-post-id]">
<a href="[wpv-post-url]" class="btn btn-info" data-toggle="modal" data-target="#[wpv-post-id]"><div class="imageclass"><img src="[wpv-post-featured-image output="url" size="medium"]" /></div><h4>[wpv-post-title]</h4></a>
</button>

// this is what appears in the modal
<div class="modal fade xmit-modal-sm-[wpv-post-id]" tabindex="-1" role="dialog" aria-labelledby="[wpv-post-title]" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
			  // can be any HTML content
        </div>
    </div>
</div>

Visto en https://gist.github.com/davekuhar/648266b99953828c252778581ce3e7cc

Libreria Select 2 en Toolset

Llamamos a la librería Select 2

function enqueue_select2_jquery() {
    wp_register_style( 'select2css', '/wp-content/themes/tastal/js/select2.min.css', false, '1.0', 'all' );
    wp_register_script( 'select2', '/wp-content/themes/tastal/js/select2.min.js', array( 'jquery' ), '1.0', true );
    wp_enqueue_style( 'select2css' );
    wp_enqueue_script( 'select2' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_select2_jquery' );

En el apartado donde está la búsqueda personalizada (Search and Pagination) nos vamos al editor JS

jQuery( document ).ready(function() {
    jQuery('.select').select2();
});

Luego en el filtro ponemos la clase select y el estilo select2 y listos.

Ya tenemos funcionando el desplegable de la búsqueda personalizada con la librería select2

Deactivate submit button in Toolset custom search

Submit button deactivated when custom search is loaded

jQuery( document ).ready( function() {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.form (object) The jQuery object for the View form
    * data.update_form (bool) Whether the custom search form will be updated
    * data.update_results (bool) Whether the custom search results will be updated
    */
   var $ = jQuery;
    $('input[type="submit"]').prop('disabled', true);    
});

Activate the button

jQuery( document ).on( 'js_event_wpv_parametric_search_triggered', function( event, data ) {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.form (object) The jQuery object for the View form
    * data.update_form (bool) Whether the custom search form will be updated
    * data.update_results (bool) Whether the custom search results will be updated
    */
   var $ = jQuery;
    $('input[type="submit"]').prop('disabled', true);
});
Scroll al inicio

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.