• When I click on Contact Form, the list of Forms comes up in Ascending Date Order, is there way to set the default view to be Descending Date Order.

    Thanks

Viewing 1 replies (of 1 total)
  • Hello @hashah3

    Contact Form 7 doesn’t actually sort by date by default, it sorts by Title, A to Z. It just looked like date order because it could be your forms happened to be named in the order they were created. Either way, the fix below solves it by forcing the list to always show newest-first.

    The code:

    add_action( 'pre_get_posts', function( $query ) {
    if ( ! is_admin() ) {
    return;
    }
    if ( 'wpcf7_contact_form' !== $query->get( 'post_type' ) ) {
    return;
    }
    $query->set( 'orderby', 'date' );
    $query->set( 'order', 'DESC' );
    } );

    How to add it, pick whichever is easiest for you:

    Option 1: WPCode plugin (easiest, no coding risk)

    1. Install the free “WPCode” plugin from Plugins → Add New (if not already installed).
    2. Go to Code Snippets → Add Snippet.
    3. Choose “Add Your Custom Code (New Snippet)”.
    4. Paste the code above into the code box.
    5. Set the type to PHP Snippet.
    6. Under “Insertion”, leave it as “Auto Insert” / “Run Everywhere”.
    7. Click Save Snippet, then toggle it to Active.
    8. Go check Contact → Contact Forms — the newest form should now be at the top.

    Option 2: Your theme’s functions.php file

    1. Go to Appearance → Theme File Editor (or use FTP/File Manager).
    2. Open functions.php for your active theme.
    3. Paste the code at the very bottom of the file.
    4. Save.

    I’d recommend Option 1 (WPCode): it’s safer, since a typo in functions.php can break the whole site, while a bad snippet in WPCode can just be deactivated with one click.

    Thank You

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.