INSIGHTS / Case Study

Case Study / / 8 min read

Using WordPress to Automate Cover Letter Requests at the RT/RW Level

How we used Custom Post Types, user roles and free plugins to move neighborhood cover letter requests online.

SCND DigitalWordPress & Webflow studio
Tampilan website Urusan RT/RW: beranda, dashboard warga, dan surat pengantar

WordPress started out as a blogging platform. It has since grown into a content management system (CMS) that can handle a wide range of needs.

A few core features make WordPress a flexible CMS that can be adapted to many different requirements:

  1. Custom Post Types: Beyond the built-in content types (Posts and Pages), WordPress lets you create Custom Post Types for more specific content.
  2. User Roles and Capabilities: WordPress has a user role system with different levels of access.
  3. Plugin Ecosystem: The large WordPress plugin ecosystem offers thousands of extensions for adding new functionality.

How We Used These WordPress Features for Cover Letter Requests

In Indonesia, residents often need a cover letter (surat pengantar) from their RT/RW (neighborhood and community units) before they can apply for documents at the village office. In this project, we used the WordPress features above as follows:

  1. Custom Post Types:
    1. Submission: Stores the letter requests submitted by residents.
    2. Layanan (Services): Stores information about the services offered by the Kelurahan (village office).
    3. Form Layanan (Service Form): Displays the form residents fill in to request a letter for a specific service.
  2. User Roles:
    1. Warga (Resident): Can register, browse services and submit letter requests.
    2. Pengurus RT/RW (RT/RW officer): Can verify and manage letter requests, and schedule meetings with residents.
    3. Site Admin: Responsible for running the site as a whole, including managing users and content.
  3. Plugins:
    1. Advanced Custom Fields (PRO): Adds custom fields to Custom Post Types and user profiles to store the extra information we need.
    2. Custom Post Type UI: Makes it easy to create and manage Custom Post Types from the WordPress admin.
    3. Document Engine: Generates the cover letters as PDFs automatically.
    4. Frontend Admin: Lets residents and RT/RW officers work with the system through forms on the frontend of the site.
    5. User Role Editor: Gives finer control over access rights and permissions for each user role.

Below are some screenshots, with a short explanation of the changes we made.

Homepage

Homepage

Access Permissions

To make sure only users with certain roles can open specific pages, we used the following code:

//Check whether the user is logged in
if (!is_user_logged_in()) {
    wp_safe_redirect(home_url());
    exit;
}

//Check whether the user is a Resident / RT officer / RW officer
if (is_user_logged_in()) {
    $user = wp_get_current_user();
    $user_roles = (array) $user->roles;
    if (!current_user_can('administrator') && !in_array('pengurus-rt', $user_roles)) {
        wp_safe_redirect(home_url('/dashboard/'));
        exit;
    }
} else {
    wp_safe_redirect(home_url());
    exit;
}

//Redirect logged-in users to the Dashboard
function redirect_logged_in_users_to_dashboard()
{
    if (is_user_logged_in() && is_front_page()) {
        $dashboard_page_id = 321; // Replace 123 with the actual ID of your "Dashboard" page
        wp_redirect(get_permalink($dashboard_page_id));
        exit;
    }
}
add_action('template_redirect', 'redirect_logged_in_users_to_dashboard');


//Make the WP Dashboard accessible only to the main Admin (user id 1)
function restrict_admin_access()
{
    $current_user = wp_get_current_user();

    // Check if the user is in the admin area and not user ID 1
    if (is_admin() && $current_user->ID != 1) {
        wp_redirect(home_url()); // Redirect to the homepage
        exit; // Prevent further execution
    }
}
add_action('admin_init', 'restrict_admin_access');

Dashboard

This page shows a summary of the user’s profile, short news updates from the admin and a list of the requests they have submitted.

Dashboard

Services Page

Services page

Services

<?php
//If the user is logged in, show a link to the form submission page
if (is_user_logged_in()) {
    global $current_user;
    get_currentuserinfo(); ?>
    <?php
    $relatedForms = get_field('form');
    if ($relatedForms) {
        $relatedForm = $relatedForms[0];
        $permalink = get_permalink($relatedForm->ID);
        $title = get_the_title($relatedForm->ID);
    ?> <span class="layPengantar">
            <a href="<?php echo esc_url($permalink); ?>">Buat Pengantar</a>
        </span>
    <?php }  ?>
<?php } ?>

<?php 
//If the Layanan post has a PDF field, show a Download link
if (get_field('pdfLink')) : ?>
    <span class="layDownload">
        <a href="<?php the_field('pdfLink'); ?>" target="_blank">Download</a></span>
    </span>
<?php endif; ?>

Form Submission

On the request page, residents see their profile information again along with the requirements for the letter. To make sure each request reaches the right RT/RW officers, we added RT and RW taxonomies (categories) to the “Submission” post type. These taxonomies sit in hidden fields and are filled in automatically from the RT and RW details in the resident’s profile.

Service form

Service form

We used the ACF Form function from the Advanced Custom Fields plugin to display ACF field groups on the frontend, so residents can fill in the request form easily.

//Get the USER ID and display the required data
$user_ID = get_current_user_id();
$rt = get_field('rt', 'user_' . $user_ID);
$rw = get_field('rw', 'user_' . $user_ID);
$alamat = get_field('alamat', 'user_' . $user_ID);
$tempatlahir = get_field('tempat_lahir', 'user_' . $user_ID);
$tanggallahir = get_field('tgl_lahir', 'user_' . $user_ID);

//Display the date in Indonesian date format
setlocale(LC_TIME, 'id_ID');
$formatted_date = strftime('%d %B %Y', strtotime($tanggallahir));

$gender = get_field('gender', 'user_' . $user_ID);
$agama = get_field('agama', 'user_' . $user_ID);
//call other data here... 

acf_form_head();

We added some JavaScript that automatically assigns each published letter request (post) to the matching RT/RW taxonomy.

window.onload = function () {
    const radioRTs = document.querySelectorAll('[data-taxonomy="rt"] ul.acf-checkbox-list li label input[type="radio"]');
    const chooseuserRT = document.getElementById("userRT");
    const radioRWs = document.querySelectorAll('[data-taxonomy="rw"] ul.acf-checkbox-list li label input[type="radio"]');
    const chooseuserRW = document.getElementById("userRW");

    function setRTRadio(text) {
        for (const radioRT of radioRTs) {
            const labelText = radioRT.nextElementSibling.textContent.trim();
            if (labelText === text) {
                radioRT.checked = true;
                return;
            }
        }
        console.warn("Option text not found in radio button group:", text);
    }
    setRTRadio(chooseuserRT.textContent);

    function setRWRadio(text) {
        for (const radioRW of radioRWs) {
            const labelTextRW = radioRW.nextElementSibling.textContent.trim();
            if (labelTextRW === text) {
                radioRW.checked = true;
                return;
            }
        }
        console.warn("Option text not found in radio button group:", text);
    }
    setRWRadio(chooseuserRW.textContent);
};

Once a request is linked to an RT/RW taxonomy, the system can filter requests by it. That way, RT/RW officers see only the requests from their own area in the WordPress dashboard.

Submission List

This page lists the requests submitted by the logged-in user. To build it, we used a WordPress query to fetch the relevant requests (the “Submission” post type).

To make the page clearer and easier to use, we added a few features:

  • Pagination: When there are more than 20 requests, the page shows pagination to make navigation easier.
  • Dropdown Filter: Users can filter requests by status (“Not reviewed”, “Revision”, “Scheduled” or “Rejected”) from a dropdown.
  • Requests per Status: We also show the number of requests in each status, so users get an overview of where their requests stand. These counts come from an extra query that tallies requests by status.
SubmissionList

Submission List

Main Query

<div class="listWrapper">
    <?php

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(
        'post_type' => 'submission', // Replace 'submission' with your actual custom post type
        'author' => $user_id,
        'posts_per_page' => 20,
        'paged' => $paged
    );
    if (!empty($selected_status)) {
        $args['meta_compare'] = '=';
        $args['meta_key'] = 'status';
        $args['meta_value'] = $selected_status;
    }
    $the_query = new WP_Query($args);

    if ($the_query->have_posts()) :
        while ($the_query->have_posts()) : $the_query->the_post();
            get_template_part('part/listItem'); // Ensure this template part handles your custom post type
        endwhile;
        if ($the_query->max_num_pages > 1) :
            echo '<div class="pagination">';
            echo paginate_links(array(
                'base'         => get_pagenum_link(1) . '%_%', // Adjust as needed
                'format'       => '?paged=%#%',  // Adjust as needed
                'current'      => max(1, get_query_var('paged')),
                'total'        => $the_query->max_num_pages,
                'prev_text' => __('Previous'),
                'next_text' => __('Next'),
            ));
            echo '</div>';
        endif;
    else :
        _e('Tidak ada pengajuan Surat Pengantar.'); // Adjust message as needed

    endif;

    wp_reset_postdata();
    ?>
</div>

Additional code (counting posts by status, and the dropdown for filtering by status)

<div id="PostHeading">
    <div class="subStatus">
        <?php
        $status_counts = array(
            'review' => 0,
            'revisi' => 0,
            'jadwal' => 0,
            'tolak' => 0
        );

        $count_args = array(
            'post_type' => 'submission',
            'posts_per_page' => -1,
            'tax_query' => array( 
                array(
                    'taxonomy' => 'rt',
                    'field' => 'slug',
                    'terms' => $rt
                )
            ),
            'fields' => 'ids',
        );
        $count_query = new WP_Query($count_args);

        // Count posts with each status
        if ($count_query->have_posts()) {
            foreach ($count_query->posts as $post_id) {
                $status = get_post_meta($post_id, 'status', true);
                if (array_key_exists($status, $status_counts)) {
                    $status_counts[$status]++;
                }
            }
        }
        wp_reset_postdata();
        echo "<div><span class='statReview'>" . $status_counts['review'] . "</span> review</div>";
        echo "<div><span class='statRevisi'>" . $status_counts['revisi'] . "</span> revisi</div>";
        echo "<div><span class='statJadwal'>" . $status_counts['jadwal'] . "</span> terjadwal</div>";
        echo "<div><span class='statTolak'>" . $status_counts['tolak'] . "</span> ditolak</div>";
        $selected_status = isset($_GET['status']) ? $_GET['status'] : '';
        ?>
    </div>
    <div class="subFilter">
        <form method="get">
            <select name="status" onchange="this.form.submit()">
                <option value="">Semua Status</option>
                <option value="review" <?php selected('review', $selected_status); ?>>Belum direview</option>
                <option value="revisi" <?php selected('revisi', $selected_status); ?>>Harap Revisi</option>
                <option value="jadwal" <?php selected('jadwal', $selected_status); ?>>Dijadwalkan</option>
                <option value="tolak" <?php selected('tolak', $selected_status); ?>>Ditolak</option>
            </select>
        </form>
    </div>
</div>

RT/RW Officer Query

SubmissionAdmin

Submission RT/RW

The request list on the RT/RW officer page shows the requests from their area. To do this, we changed the WordPress query to filter requests by the RT taxonomy instead of by user ID, as on the regular user page.

$rt_args = array(
    'post_type' => 'submission',
    'posts_per_page' => -1, 
    'tax_query' => array(
        array(
            'taxonomy' => 'rt',
            'field' => 'slug',
            'terms' => $rt
        )
    ),
    'fields' => 'ids', 
);
$rt_query = new WP_Query($rt_args);

RT/RW officers can then edit the requests residents have submitted, including changing a request’s status.

EditSubmission

Edit Submission

Once a request is scheduled, both residents and officers get “Print” and “Download PDF” links, so residents can print the cover letter or save it as a PDF. Officers also get a shortcut to a wa.me link for contacting residents on WhatsApp.

The print page is a dedicated view of a single request (single-submission). It shows the resident’s details, including personal information and the specifics of the request, plus a button for printing a paper copy.

SubmissionPrint

Submission Print

We used the Document Engine plugin to generate PDF documents from the letter requests.

SubmissionPDF

Submission PDF

That wraps up this case study on how WordPress, with Custom Post Types, user levels and free plugins, can simplify the process of requesting official letters.

Want more tips and tricks on WordPress, UI/UX, marketing and social media? Follow our Facebook page for the latest updates.

NEED A MORE SPECIFIC ANSWER?

We’ll check your website for free.

Send us your website address. We’ll give you a picture of its condition and recommendations you can act on right away.

Check my website