Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter Sean T.

    (@tinothepro)

    @atanasangelovdev ,

    I am currently using the Genesis Framework so I don’t work in multiple templates. Everything is primarily done using hooks so here is the code in my functions.php.

    use Carbon_Fields\Container;
    use Carbon_Fields\Field;
    
    add_action( 'after_setup_theme', 'crb_load' );
    function crb_load() {
        require_once( 'carbon-fields/vendor/autoload.php' );
        \Carbon_Fields\Carbon_Fields::boot();
    }
    
    // Add carbon fields
    add_action('carbon_fields_register_fields', 'crb_register_custom_fields');
    function crb_register_custom_fields() {
    // You can assume these are correctly defined Atanas
      include_once(dirname(__FILE__) . '/includes/hero.php');
    }
    
    // Display hero
    add_action('genesis_header', 'add_hero');
    function add_hero() { ?>
      <div class="hero-content">
        <div class="wrap">
          <?php
          if (carbon_get_post_meta(get_the_ID(), 'hero_headline')) { ?>
            <h1><?php echo carbon_get_post_meta(get_the_ID(), 'hero_headline'); ?></h1>
          <?php }
          if (carbon_get_post_meta(get_the_ID(), 'hero_teaser')) { ?>
            <p><?php echo carbon_get_post_meta(get_the_ID(), 'hero_teaser'); ?></p>
          <?php } ?>
        </div>
      </div>
      <?php }
    Thread Starter Sean T.

    (@tinothepro)

    Hi @atanasangelovdev,

    Here is a screenshot of the database records:

    https://ibb.co/diH2ra

    I have created 2 digital fields and 1 physical.

    Here’s an example of how the data is stored differently:

    meta key: content_1_text
    meta key: _sections|content_section_text|1|0|value

    By following the documentation I should be able to access the data using complexfield[groupnumber]:namedgroup/field if I understand correctly. There are no examples of retrieving complex data on the site.

    By saying nested field values aren’t able to retrieve legacy data, does that mean all of business I have done using CF version < 2 will not be able to utilize version 2 at all?

    To install carbon fields I have ran the composer script on the directory WordPress is installed. I am able to retrieve values using the get_post_meta() WP function but not able to use any carbon_get_* . Thanks for your help.

    • This reply was modified 7 years, 7 months ago by Sean T..
    Thread Starter Sean T.

    (@tinothepro)

    I’ve also tried my best to use the :

    https://carbonfields.net/docs/advanced-topics-field-name-patterns/?crb_version=2-0-0

    But I still get …./functions.php:256:boolean false from my var_dump() on any combination of pattern I try. I’ve tried all the ones in the documentation. What I’ve tried are things like:

    Container::make( 'post_meta', 'Slider Data' )
        ->where( 'post_type', '=', 'page' )
        ->add_fields( array(
          Field::make( 'complex', 'crb_services' )
        ->add_fields( 'digital', array(
            Field::make( 'text', 'name' ),
        ) )
        ->add_fields( 'physical', array(
            Field::make( 'textarea', 'name' ),
        ) )
        ));

    var_dump(carbon_get_post_meta(get_the_ID(), 'crb_services[0]:digital/name'));

    Thread Starter Sean T.

    (@tinothepro)

    @atanasangelovdev sure thing. Let me know if you need additional information. These container/field definitions are in my plugin and I have no problem displaying their contents when using echo carbon_get_the_post_meta( ‘crb_some_post_field’ ); from inside the plugin.

    I’ll link a gist here that shows the definition, initialization, and implementation in case you need more frame of reference.

    https://gist.github.com/tinothepro/d43611ae20c307b30a4c72c1f52fd023

    I appreciate all your help!

    Thread Starter Sean T.

    (@tinothepro)

    Hi @atanasangelovdev,

    I had one more additional question regarding this. I tried several variations of adding this into the loop but have been unsuccessful in retrieving any data.

    <?php while ( have_posts() ) : the_post(); ?>
        <div class="result">
          <span class="search-post-title">
           <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
          </span>
          <p><?php echo carbon_get_the_post_meta( 'content_section_column1' ); ?></p>
          <span class="search-post-excerpt"><?php the_excerpt(); ?></span>
       </div>
     
      <?php endwhile; ?>

    These fields are located in a simple builder plugin. Is there something I’m missing with this? Following your example did not output anything. I realized I’m not able to pull any of the meta information from the plugin even from functions.php. Ideas?

    • This reply was modified 7 years, 8 months ago by Sean T..
    Thread Starter Sean T.

    (@tinothepro)

    Hi @atanasangelovdev,

    Thanks for replying so quickly. What you said makes complete sense. Are you aware of any example search templates using CF? I am just thinking in terms of how a normal WP search returns a title and an excerpt (pretty standard), if you have multiple CF metaboxes set up and maybe some pages have different ones, how you’d query for all these and their variances (It’d be more than just the_excerpt()). I appreciate any resources or help you can provide.

    Sean T.

    (@tinothepro)

    Hi @bankimoon,

    I am trying to solve this same issue. Did you ever end up coming up with a solution?

    Thread Starter Sean T.

    (@tinothepro)

    Hi,

    An error on my part. ->show_on_page( (int) get_option( ‘page_on_front’ ) ) actually did work for me to target only the home page.

    Thread Starter Sean T.

    (@tinothepro)

    Hi Atanas,

    Essentially when I worked with ACF it had an extension plugin that allowed Yoast SEO to recognize the content in the custom fields. This would allow it to properly judge the content in these fields base on SEO criteria in situations where most of the content was NOT in the WordPress editor. In my trials with CF I have noticed that Yoast does not recognize any content that is in these custom fields. This makes it harder for clients to judge the quality of the content they write and better implement good SEO practices. Is there a way to get Yoast to see the content inside my various CF custom fields? I hope this clarifies a bit better. Thanks!

    Thread Starter Sean T.

    (@tinothepro)

    Hi Atanas,

    I did yesterday and it was not working. I also noticed yesterday that the first item had 2 dashes in the hamburger where as the rest had 3. Wonder if this was why it wasn’t working? I tried this morning after reading your post and it works. Kind of puzzled on why this was as my whole team here at the office tried it yesterday. Maybe a bug that I can’t replicate again. Thank you so much for your help!

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