Looper from Custom DB Table

I have a custom database table with info I’d like to display. Is it possible to do this with loopers?

Hi @gstertz,

Thanks for reaching out.
What you are trying can be done using the Custom Looper which is a custom function that returns the values you want. You can go through the following thread where the custom loopers are explained.




I would also suggest you go through the following article to understand the Custom Looper.


Hope it helps.
Thanks

Thank you! I made this and it works!

add_filter( 'cs_looper_custom_clients', function( $result, $params ) {
global $wpdb;

// Corrected table name
$table_name = $wpdb->prefix . 'crm_clients';
$clients = $wpdb->get_results("SELECT * FROM $table_name");

$result = [];
foreach ($clients as $client) {
	$result[] = [
		'client_id' => $client->client_id,
		'first_name' => $client->client_first_name,
		'last_name' => $client->client_last_name,
		'email' => $client->client_email,
		'phone' => $client->client_phone,
		'address_1' => $client->client_address_1,
		'address_2' => $client->client_address_2,
		'city' => $client->client_city,
		'state' => $client->client_state,
		'zip' => $client->client_zip,
		'brand_1' => $client->client_brand_1,
		'brand_2' => $client->client_brand_2,
		'tags' => $client->client_tags,
		'lists' => $client->client_lists,
	];
} return $result; }, 10, 2);

And using these looper keys:

{{dc:looper
key=“client_id”}}
{{dc:looper
key=“first_name”}}
{{dc:looper
key=“last_name”}}
{{dc:looper
key=“email”}}
{{dc:looper
key=“phone”}}
{{dc:looper
key=“address_1”}}
{{dc:looper
key=“address_2”}}
{{dc:looper
key=“city”}}
{{dc:looper
key=“state”}}
{{dc:looper
key=“zip”}}
{{dc:looper
key=“brand_1”}}
{{dc:looper
key=“brand_2”}}
{{dc:looper
key=“tags”}}
{{dc:looper
key=“lists”}}

Hey @gstertz,

We’re glad that you’re able to figure it out.

Cheers!

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