Is there a way to know in which pages has a certain global block been used/ inserted?

Hi

What the title says.

Hi there,

You will need to run this code on your database management system:

SELECT posts.ID, posts.post_title FROM wp_posts as posts 
LEFT JOIN wp_postmeta postmeta ON posts.ID = postmeta.post_id 
WHERE postmeta.meta_value LIKE '%"global_block_id":"[ID OF GLOBAL BLOCK]"%' 
AND posts.post_type != 'revision'

If you’re familiar with SQL this should come in rather easily for you, but if not, don’t let that code overwhelm you. Here are the steps you need to follow:

  1. Go to your cPanel and locate the PHPmyAdmin. This will allow you to access your site’s database.
  2. Go to the database that is running your Wordpress site.
  3. Find the “prefix” your database is using. In my example above, you’ll see wp_posts and wp_postmeta on the code. Both of them use the wp_ table prefixes, which is the default in Wordpress.

On the left sidebar of your PHPMyAdmin, you’ll see the list of tables like below.

If you see both wp_posts and wp_postmeta, you’re 90% done. IF you have something different, for example if your prefix is abcd_, then you need to change the wp_posts to abcd_posts and wp_postmeta to abcd_postmeta on the code above.

  1. Now, we will be running that code in a little while. But before that you’ll need to go to your site. Go to Global Blocks. Then look at the ID of the Global Block you want to search for.

The image below shows what the Global Block IDs are:

Now, let’s say that the Global Block with an ID of 163, change the part of the code that says [ID OF GLOBAL BLOCK] to 163.

  1. Now, you’re ready to run the code. To do that, follow this tutorial https://www.siteground.com/tutorials/phpmyadmin/query/. Then use the code above, along with the edits discussed.

The result will be a list of ID and Title of the pages/posts that have used the Global Block. I think those will be enough to lead you to the right direction.

Hope this helps.

Hi @benursal,

Thank you for such a detailed and comprehensive solution, it has worked fine for me.

I believe this could be a great addition to PRO’s UI, to be able to see where (pages, posts, etc.) global blocks have been used in. Some of them can have CSS properties that inherit values from the section, row or column they have been inserted in. When a global block has been placed in many different locations, things can get out of control very quickly.

For example, if we change one of those global blocks (its HTML, CSS or JS) we should be able to quickly check how those changes affect the pages in which that global block is present. I think that a list of direct links to those pages from the global block edit page (PRO admin backend UI) would be very useful.

Thanks!

Good suggestion, Abarka. I’ll forward that as feature request.

Thanks @christian_y!

You’re welcome, Abarka. Have a great day!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.