A client mine asked me to find which pages on his website use gravity Forms.

This was an interesting question and I, as always, I usually have the answer (usually more than one but in this case one is good enough).

The solution is to execute a search database query in WordPress posts table.

Here's a video explanation

In this example I am assuming that your site is using the default WordPress table prefix which is 'wp_'.
You can find what the current db table prefix by opening wp-config.php file and search for '$table_prefix' variable.
If your db table prefix is different then you'll need to replace 'wp_posts' with {YOUR_PREFIX}_posts below.

The search can be a partial match of the GravityForms shortcode because the shortcode can contain parameters.
The search in WordPess posts table will also reveal which pages or posts are using the shortcode.

You may need this information because you want to switch to a different form plugin or remove it if you don't want to GraivityForms anymore.

The search query that searches for the GravityForms shortcode looks like this.
You can run it in phpMyAdmin

SELECT ID, post_title FROM wp_posts WHERE post_content LIKE \"[gravityform%\"

If you prefer to use WP-CLI you can run this in the command line.

wp db query 'SELECT ID, post_title FROM mswp_posts WHERE post_content like "[gravityform%"' --skip-column-names

 

My particular solution was to create a simple script that I have installed as a system WP plugin (mu-plugin).
It calls WP CLI and lists what it has found.
If you want to go this route create a file in wp-content/mu-plugins/gf_search.php

<?php

if (isset($_REQUEST['my_gf_search'])) {
	$cmd = "/usr/local/bin/php /usr/local/bin/wp db query 'SELECT ID, post_title FROM wp_posts WHERE post_content like \"[gravityform%\"' --skip-column-names";
	$res = `$cmd 2>&1`;
	$res = htmlentities($res, ENT_QUOTES, 'UTF-8');
	echo "<pre>";
	echo "$res";
	echo "</pre>";
	die(__LINE__.__FILE__);
}

To run it access your site as follows.
http://example.com/?my_gf_search

The result should show Page/Post ID and Post Title.

gravityforms php search result

Note: In the php script above I have used the full paths to both php & WP-CLI because the hosting was running cPanel and it has multiple php binaries and only this one works properly. The other ones output content-type or take too much time to load.

After you find which pages/posts use GravityForms then you can either search by their title OR get to them directly by editing this link.

Make sure you replace your site and the ID that you've found during the search.

http://example.com/wp-admin/post.php?post=ENTER_ID_HERE&action=edit

 

Related

 

Is there a better solution?

Do you need any of the code in this post customized or packaged into a plugin? Get a free quote