Skip to content

Commit

Permalink
add shortcode to load programs
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiaDv491 committed Mar 21, 2021
1 parent 3f02e5e commit 96ccaa8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions includes/class-isceb_wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ private function define_public_hooks()
*/

$this->loader->add_shortcode("wiki-form", $plugin_public, "shortcode_wiki_submit", $priority = 10, $accepted_args = 2);
$this->loader->add_shortcode("wiki-programs", $plugin_public, "shortcode_wiki_programs", $priority = 10, $accepted_args = 2);

// Template page courses
//Uncomment to register custom post type course
Expand Down
20 changes: 19 additions & 1 deletion public/class-isceb_wiki-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ function shortcode_wiki_submit($atts)
return ob_get_clean();
}

function shortcode_wiki_programs($atts)
{
$args = shortcode_atts(
array(
'arg1' => 'arg1',
'arg2' => 'arg2',
),
$atts
);

$var = (strtolower($args['arg1']) != "") ? strtolower($args['arg1']) : 'default';
ob_start();
include plugin_dir_path(__FILE__) . 'partials/isceb_wiki_programs_shortcode.php';
// $my_content = ob_get_contents();
// var_dump(file_exists(plugin_dir_path(__FILE__) . 'partials/isceb_wiki_programs.php'));
return ob_get_clean();
}

function locate_template($template, $settings, $page_type)
{

Expand Down Expand Up @@ -262,7 +280,7 @@ public function rewrite_wiki_base_url_to_page()
//get_option returns false by default if option doesn't exist
$options = get_option('isceb_wiki-test');
if ($options && $options['en']['wiki_home_1'] === null && $options['en']['wiki_home_1'] == '') {
error_log( 'i am here bitch');
error_log('i am here bitch');
$page = get_page_by_title('Wiki Homepage');
error_log($page->ID);
if ($page === null) {
Expand Down
45 changes: 45 additions & 0 deletions public/partials/isceb_wiki_programs_shortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/

$get_wiki_programs = get_posts(array(
'post_type' => 'program'
));

if ($get_wiki_programs) {
foreach ($get_wiki_programs as $get_wiki_program) {
$get_wiki_phases = get_posts(array(
'post_type' => 'phase',
'meta_query' => array(
array(
'key' => 'program', // name of custom field
'value' => '"' .$get_wiki_program->ID . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));

var_dump($get_wiki_phases
);

if( $get_wiki_phases ): ?>
<p><?php echo($get_wiki_program->post_title); ?></p>
<ul>
<?php foreach( $get_wiki_phases as $get_wiki_phase ): ?>

<li>
<!-- <p > The title of the file </p> -->
<a href=" <?php echo get_permalink($get_wiki_phase->ID); ?>"> <?php echo $get_wiki_phase->post_title; ?> </a>

</li>
<?php endforeach; ?>
</ul>
<?php endif;

}
}


0 comments on commit 96ccaa8

Please sign in to comment.