Note that there are some explanatory texts on larger screens.

plurals
  1. POGroup Custom Fields in meta boxes together for displaying as rows in a grid?
    text
    copied!<p>I have a custom post type I made for Products. It will have 10 custom field types like so:</p> <p>DocName1<br> DocUrl1</p> <p>DocName2<br> DocUrl2</p> <p>... and so on. Here's the code for the custom post type meta boxe for the custom fields:</p> <pre><code>//* Add custom Meta Boxes for Products *// $prefix = 'aps_'; //To prevent conflicts with other plugins $meta_box = array( 'id' =&gt; 'products-meta-boxes', 'title' =&gt; "Product Details", 'page' =&gt; 'tf_products', //attach to products custom post 'context' =&gt; 'normal', 'priority' =&gt; 'high', 'fields' =&gt; array( array( 'name' =&gt; 'Document Name 1', 'desc' =&gt; 'Name of PDF or Document you want to share', 'id' =&gt; $prefix . 'docname1', 'type' =&gt; 'text', 'std' =&gt; '' ), array( 'name' =&gt; 'Document URL 1', 'desc' =&gt; 'Web Address to PDF or document you want to share', 'id' =&gt; $prefix . 'docurl1', 'type' =&gt; 'text', 'std' =&gt; 'http://' ), array( 'name' =&gt; 'Document Name 2', 'desc' =&gt; 'Name of PDF or Document you want to share', 'id' =&gt; $prefix . 'docname2', 'type' =&gt; 'text', 'std' =&gt; '' ), array( 'name' =&gt; 'Document URL 2', 'desc' =&gt; 'Web Address to PDF or document you want to share', 'id' =&gt; $prefix . 'docurl2', 'type' =&gt; 'text', 'std' =&gt; 'http://' ) ) ); </code></pre> <p>I'd like to group them together like <code>DocName1 - DocUrl1</code> so they can be echo'd out on a single line of a grid as textboxes. I've got a grid ready on my custom post type add/edit form that I want to put textboxes in so they can be added or edited. Screenshot here <a href="http://i.stack.imgur.com/ZGqGI.png" rel="nofollow">http://i.stack.imgur.com/ZGqGI.png</a></p> <p>I can easily do a <code>foreach ($meta_box['fields'] as $field)</code> and echo out the text box for each one, but that is for EACH FIELD, not a group (like DocName1 and DocUrl1), but I want <code>DocName1 - DocUrl1</code> on the same grid line. Is there a way to do this? I can't wrap my head around an efficient way to do this.</p> <p>The way I'm doing it now is like so:</p> <pre><code>foreach ($meta_box['fields'] as $field) { // get current post meta data $meta = get_post_meta($post-&gt;ID, $field['id'], true); echo '&lt;tr&gt;', '&lt;th style="width:20%"&gt;&lt;label for="', $field['id'], '"&gt;', $field['name'], '&lt;/label&gt;&lt;/th&gt;', '&lt;td&gt;'; echo '&lt;input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" /&gt;', '&lt;br /&gt;', $field['desc']; echo '&lt;/td&gt;', '&lt;/tr&gt;'; } </code></pre> <p>But of course this echo's out each field on its own line. I want a grid with DocName1 and DocUrl1 on the first gridline, then DocName2 and DocUrl2 on the second, and so on.</p> <p>Sorry if this is confusing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload