Shuffle Filter – Remove scroll bar in “Group by Taxonomy” type (checkboxes)

With the Shuffle Filter feature, you can show categories, tags and custom taxonomies as options in several types to filter result. When you show options as checkboxes, the scrollbar will be shown if there are a lot of options (see demo).
To show all options without scrollbar, Please add this code to Custom CSS field (the left textarea) in Content Views >> Settings page:

.pt-cv-filter-group ul {max-height: 500px;}

Best regards,

WooCommerce – show “Out of stock” text on products

Content Views Pro helps you to show WooCommerce products in grid and list layout easily.
For products which you don’t have in stock anymore, you might want to show the “Out of stock” text. To do that, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

// Content Views Pro - Woocommerce: Display Out of Stock badge
add_action( 'pt_cv_item_extra_html', 'cvp_item_extra_html_wofs' );
function cvp_item_extra_html_wofs( $post_id ) {
	$product = wc_get_product( $post_id );
	if ( is_object( $product ) ) {
		if ( !$product->is_in_stock() ) {
			echo '<div class="out-of-stock">Out of stock</div>';
		}
	}
}

Best regards,

Live Filter – set default sort option

With the Live Filter feature in Pro version, you can show sort options in frontend, to help your users to sort content themselves.
To set the default sort option, please add this code to Custom JS field (the right textarea) in Content Views >> Settings page:

var viewid = 'VIEW_ID', default_sort = 'SORT_VALUE';
if ($('[data-sid="' + viewid + '"] [name="_orderby"]').val() == '') {
    $('[data-sid="' + viewid + '"] [name="_orderby"]').val(default_sort).trigger('change');
}

then:

  • replace VIEW_ID with ID of your View
  • replace SORT_VALUE with the sort option you want to set as default, it can be title, date, or custom field key (to get correct custom field key, select that field from the live filter, the URL will change to ?_orderby=FIELD_KEY, then copy the FIELD_KEY in URL).

Best regards,

How to show Recurring events of Events Manager plugin

The Events Manager plugin considers normal events and recurring events are 2 different post types.
Content Views Pro can help you to show events of the Events Manager plugin easily (read more).
The recurring events are not publicly queryable by default. So you won’t see the “Recurring Events” as an option of the “Content Type” setting when creating a View.

To make recurring events publicly queryable, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

add_filter( 'em_cp_event_recurring_public', '__return_true' );
add_filter( 'em_cp_event_recurring_publicly_queryable', '__return_true' );

Then in a View, you can select “Recurring Events” as option of “Content Type” to show recurring events.

Best regards,

Live Filter – translate text of the Submit, Reset button

With Content Views Pro 5.3.2 and before, you can translate text of the Submit, Reset button using the translation feature of WordPress (read more).

Since Content Views Pro 5.3.3 and after, you can translate text of these buttons quickly and easily using JavaScript variables. Please add this code to Custom JS field (the right textarea) in Content Views >> Settings page:

window.cvp_lf_submit_text = 'Your Submit Text';
window.cvp_lf_reset_text = 'Your Reset Text';

Best regards,

Show Custom Field – show more info of ACF post object

Content Views Pro helps you to show custom fields easily.
When showing a post object custom field of the Advanced Custom Fields plugin, Content Views Pro will show the title of the object by default.
To show more info of the object, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

add_filter( 'pt_cv_acf_post_object_html', 'cvp_theme_acf_post_object_html', 100, 2 );
/**
 * Content Views Pro - show more info of ACF post object
 * @param string $args The output of this ACF field (default output is the post title)
 * @param object $post The post object
 * @return string
 */
function cvp_theme_acf_post_object_html( $args, $post ) {
	global $pt_cv_id;
	if ( $pt_cv_id === 'VIEW_ID' ) {
		// For example: show thumbnail before title
		$args = get_the_post_thumbnail( $post->ID ) . $args;
	}

	return $args;
}

(replace VIEW_ID with ID of your View)

Best regards,

Add “title” attribute to links

For SEO purposes, many researches state that title attribute might not be given much weight in ranking.
For user’s experience, the title attribute can provide descriptive text (or supplementary information) to the link.

To add title attribute to links in grid or list of Content Views, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

// Content Views Pro - add Title attribute to images
add_filter( 'wp_get_attachment_image_attributes', 'cv_add_tilte_for_image', 100, 3 );
function cv_add_tilte_for_image( $attr, $attachment, $size ) {
	global $post;
	if ( isset( $post->post_title ) ) {
		$attr[ 'title' ] = $post->post_title;
	}
	return $attr;
}
// Content Views Pro - add Title attribute to links
add_filter( 'pt_cv_field_href_attrs', 'cvp_theme_add_title_to_links', 100, 3 );
function cvp_theme_add_title_to_links( $custom_attr, $open_in, $oargs = array()  ) {
	global $post;
	if ( isset( $post->post_title ) ) {
		$custom_attr[] = "title='{$post->post_title}'";
	}
	return $custom_attr;
}

Best regards,

WooCommerce – hide products which are restricted to members of WooCommerce Memberships plugin

Content Views Pro helps you to show any WooCommerce products easily.

This document is used to hide product is restricted to members of WooCommerce Memberships plugin.

Please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

// Content Views Pro - Hide product is restricted to members of WooCommerce Memberships
add_filter( 'pt_cv_show_this_post', 'cvp_theme_support_woomembership', 100, 1 );
function cvp_theme_support_woomembership( $args ) {
	if ( wc_memberships_is_product_viewing_restricted( $args->ID ) || wc_memberships_is_post_content_restricted( $args->ID ) ) {
		$args = 0;
	}
	return $args;
}

Best regards,

Add translation of View with Polylang plugin

The Polylang plugin helps you to create multilingual WordPress website.
And our Content Views Pro plugin helps you to show WordPress content of these languages easily.
For most case, you only need to create one View for all languages (read more).
But sometimes you need to create each View for each language, that is supported by Content Views Pro too.

Set language for a View

  • In the admin Content Views > All Views page, mouse over the View which you want to set language, click Edit Language:
    CVP with Polylang - edit view language
  • It will navigate you to a page, where you can select language of the View. After finishing, please click the Update button.

Add translation of a View

For example, you have a View in English, now you want to create the same purpose View in Deutsch, please follow these steps:

  • In the admin Content Views > All Views page, click on the plus “+” icon to add a translation of a View:
    CVP with Polylang - add translation of View
  • Enter the title of the translation View, then click Publish button:
    CVP with Polylang - add title of the translation View
  • The translation View will be created, click the
    [Content Views] Filter Posts Now
    button:
    CVP with Polylang - edit the translation View
  • Notice: This step and below step are required. If not, the translation View won’t be created successfully.

  • It will navigate to the View settings page, change settings there to filter content in new language, then click the Save button:
    CVP with Polylang - filter content of new language

Best regards,