Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection and repeater issue #44

Open
dimahali opened this issue Jun 23, 2017 · 5 comments
Open

Connection and repeater issue #44

dimahali opened this issue Jun 23, 2017 · 5 comments

Comments

@dimahali
Copy link

i am getting following error while querying for repeater

Call to a member function get() on null

here is my query
$post->acf->repeater('activity_details')

i guess it is because of not getting type of field required in Repeater class fetchFields function


In repeater.php following function is calling get on $field which is null
as   FieldFactory::make is returning null becuse of type not found

protected function fetchFields($fieldName, Builder $builder)
    {
        $fields = [];
        foreach ($builder->get() as $meta) {
            $id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName);
            $name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id);

            $post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post;
            $field = FieldFactory::make($meta->meta_key, $post);

            $fields[$id][$name] = $field->get();
        }

        return $fields;
    }

another issue is when i try to query image following error occurs

QueryException in Connection.php line 729:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main_site_db.postmeta' doesn't exist (SQL: select * from `postmeta` where `post_id` = 275 and `meta_key` = _wp_attachment_metadata limit 1)

i have created seprate connection as below

'wp' => [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'port'      => env('DB_PORT', '3306'),
            'database'  => env('DB_DATABASE', 'localhost'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => 'kiu_',
            'strict'    => false,
            'engine'    => null,
        ],

and added connection to post class

namespace App;

use Corcel\Post as Corcel;

class Post extends Corcel
{

    protected $connection = 'wp';

}

but still getting this error

If i change table prefix in laravel default connection which if for laravel error disapears but i get another error by laravel complaining about prefix..

i have same database for both laravel and wordpress but i am using prefix for only wordpress tables and laravel tables are without prefix...

@jgrossi
Copy link
Member

jgrossi commented Jun 23, 2017

@dimahali hey! try to set your wp connection name to wordpress or corcel. Corcel checks for both connection names by default ;-)

@dimahali
Copy link
Author

Thanks @jgrossi it worked but what about repeater issue? I am getting the same issue
Call to a member function get() on null

@dimahali
Copy link
Author

when i change following function in Repeater.php

protected function fetchFields($fieldName, Builder $builder)
    {
        $fields = [];
        foreach ($builder->get() as $meta) {
            $id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName);
            $name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id);

            $post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post;
            $field = FieldFactory::make($meta->meta_key, $post);
            $fields[$id][$name] = $field->get(); //old line
            $fields[$id][$name] = ($field) ? $field->get() : $meta->meta_value; //new line
        }

        return $fields;
    }

i get result but i am not getting image, instead id of image as below

Collection {#1860 ▼
  #items: array:2 [▼
    0 => array:5 [▼
      "sub_title" => "sadf"
      "sub_title_urdu" => "dsaf"
      "image" => "473"
      "details" => "sadf"
      "details_urdu" => "adsf"
    ]
    1 => array:5 [▶]
  ]
}

i guess we are not getting field type in the following line

FieldFactory::make($meta->meta_key, $post);

@dimahali
Copy link
Author

hey @jgrossi any update?

@stuartcusackie
Copy link

stuartcusackie commented Feb 26, 2021

Still a problem. Setting connection name to 'wordpress' or 'corcel' has no effect.

This was the solution for me (my repeater contained images)
9ee12a3

Hopefully they will merge the PR soon. For the moment I have to modify the code directly or use a local repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants