Modify Max Property Values to Load More Post Names/Slugs

Modify the maximum number of property values to load more post names/slugs.

Instructions

See “Where do I put snippets?” in our documentation for installation instructions.

Code

Filename: gppa-modify-max-property-and-load-more-post-names.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
 * Gravity Perks // GP Populate Anything // Modify Max Property Values to Load More Post Names/Slugs
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * This snippet increases the maximum number of property values displayed in the Form Editor for Populate Anything,
 * and also increases the number of post_name/post_slug values loaded from the database.
 *
 * Plugin Name:  GP Populate Anything — Modify Max Property Values to Load More Post Names/Slugs
 * Plugin URI:   https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 * Description:  Modify the maximum number of property values to load more post names/slugs.
 * Author:       Gravity Wiz
 * Version:      0.1
 * Author URI:   https://gravitywiz.com
 */

// Set the max number of property values to display in the editor and for post_name/post_slug queries.
$gppa_post_name_limit = 2500; // TODO: Update as per requirement.

add_filter( 'gppa_max_property_values_in_editor', function( $max_property_values ) use ( &$gppa_post_name_limit ) {
	return $gppa_post_name_limit;
} );

add_filter( 'gppa_object_type_col_rows_query', function( $sql, $col, $table_name, $object_type ) use ( &$gppa_post_name_limit ) {
	if ( $col !== 'post_name' && $col !== 'post_slug' ) {
		return $sql;
	}

	global $wpdb;

	if ( $table_name !== $wpdb->posts ) {
		return $sql;
	}

	if ( stripos( $sql, 'ORDER BY' ) === false ) {
		$sql = preg_replace(
			'/\s+LIMIT\s+\d+/i',
			' ORDER BY ID DESC LIMIT ' . absint( $gppa_post_name_limit ),
			$sql,
			1
		);
	}

	return $sql;

}, 10, 4 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.