Connection and repeater issue
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...
@dimahali hey! try to set your wp connection name to wordpress or corcel. Corcel checks for both connection names by default ;-)
Thanks @jgrossi it worked but what about repeater issue? I am getting the same issue
Call to a member function get() on null
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);
hey @jgrossi any update?
Still a problem. Setting connection name to 'wordpress' or 'corcel' has no effect.
This was the solution for me (my repeater contained images) https://github.com/corcel/acf/pull/84/commits/9ee12a3f13962f988d679a902ead9e6ee298157c
Hopefully they will merge the PR soon. For the moment I have to modify the code directly or use a local repo.