• Resolved sunder

    (@sunder)


    Recently moved a wordpress site to a new server, copied the database over.

    The Contact Form 7 plugin is broken.

    It is failing in classes.php:

    function wpcf7_contact_form( $id ) {
    	$post = get_post( $id );
    
    	if ( empty( $post ) || 'wpcf7_contact_form' != get_post_type( $post ) )
    		return false;

    get_post() is returning a NULL value. However, I know that the post with its id exists in the database (I can query it directly).

    Any idea what could be causing this issue? I’m fairly new to wordpress.

    http://wordpress.org/extend/plugins/contact-form-7/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sunder

    (@sunder)

    Just to clarify…

    The post I expect to be returned by get_post() exists in wp_posts table.

    Also, it does show up in the administration panel for Contact Form 7 (even provides me the short code to include it on a page).

    Thread Starter sunder

    (@sunder)

    This problem was caused by the following:
    We are using PearDB to connect to our local (CMS) database (DB). When we establish the link with PearDB, it selects our CMS schema. Which effectively UNselects the wordpress schema. Thus, WordPress isn’t finding the posts.
    This did not occur on the old server because the CMS DB and the WordPress DBs were all under different MySQL accounts. The PHP documentation for mysql_connect() explains this:
    “If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.”
    Now, to fix it we have a couple of options, some better than others.
    For a temporary fix (being implemented right now), we can hack the wordpress instance as per: http://wordpress.org/support/topic/cant-use-pear-db-classes-when-inside-wp-themes?replies=1
    The idea is to add mysql_select_db() in to wp-includes/wp-db.php’s query() function.
    The disadvantage to this is that the database name must be hard coded into that file. As well, it adds a performance penalty since there will be an extra database query for every one WordPress makes. Most significant, however, is that this hack will be undone every time wordpress is changed or upgraded.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘[Plugin: Contact Form 7] server migration, CF7 404 error’ is closed to new replies.